【发布时间】:2019-06-28 14:11:21
【问题描述】:
我刚刚使用 Spring 初始化程序创建了一个非常基本的 Spring Boot 应用程序,并且正在尝试。我想从 yaml 配置文件中加载一个列表,但它总是返回空。
我有一个自定义配置类
@ConfigurationProperties("example-unit")
@EnableConfigurationProperties
public class ConfigurationUnit {
public List<String> confiList = new ArrayList<>();
public List<String> getConfiList() {
return this.confiList;
}
}
我的主课是这样的
@SpringBootApplication
public class DemoApplication {
static ConfigurationUnit configurationUnit = new ConfigurationUnit();
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
List<String> hello = configurationUnit.getConfiList();
System.out.print("");
}
}
我已将 application.yaml 放入资源文件夹。
example-unit:
- string1
- string2
- hello22
我在这里和网上进行了搜索,但无法找出问题所在,我所做的任何更改都没有帮助。我知道我一定做错了什么。
【问题讨论】:
标签: java spring-boot configuration yaml