我必须从spring-boot项目的属性文件中读取一些字符串数组变量,我已经为这些数组创建了一个带有getter和setter方法的类,我不知道如何使用java1.8从property.yml文件中获取这些字符串数组变量的值
发布于 2019-11-15 00:10:31
使用@Value
在你的.yaml中
myPropertiesList: item1, item2或
myPropertiesList: >
item1,
item2在您的Java类中:
@Value("${myPropertiesList}")
String[] myPropertiesArray;或者在SpringBoot2中:
@Value("${myPropertiesList}")
List<String> myPropertiesList;使用@ConfigurationProperties
在你的.yaml中
myPrefix.myPropertiesList: item1, item2配置类:
@Configuration
@ConfigurationProperties(prefix = "myPrefix")
public class ConfigProperties {
private List<String> myPropertiesList;
}并将以下内容添加到SpringBoot配置中:
@EnableConfigurationProperties(ConfigProperties.class)https://stackoverflow.com/questions/58860752
复制相似问题