【发布时间】:2019-01-11 07:28:15
【问题描述】:
我能够从我的 Spring Boot 应用程序中的属性文件中读取('fruits' 的值),成功地使用@Value 如下。
@Value("${fruits}")
private String[] fruitarray;
从下面
文件:applicon.properties
#section_1
fruits=apple,mango,banana
#section_2
apple.native=aaaa
apple.cost=100
apple.name=xxyyzz
现在,我想知道,如何从属性文件的 section_2 动态访问键值。 我的意思是,......在我们上面的代码中,我们已经得到了水果数组,并使用@Value 将其设置为“fruitarray”。现在我将如何通过在 java/spring-boot 方式中使用 fruitarray[0] 变量来访问“apple.native”的值?
谢谢
【问题讨论】:
-
简单使用:@Value("${apple.native}")
-
你可以使用地图:看看这里mkyong.com/spring3/spring-el-lists-maps-example
-
试试这个方法:stackoverflow.com/a/11321542/2652269使用分隔符','
标签: java spring spring-boot properties properties-file