【发布时间】:2019-08-21 23:40:48
【问题描述】:
我需要创建 @ConfigurationProperties 来读取包含复杂对象列表的 .yml 文件。
Spring-Boot 似乎遇到了一些问题,所以我一步一步尝试先加载字符串列表:
.yml:
qwer: asdf
strings:
- Apple
- Orange
- Strawberry
- Mango
配置类:
@Component
@PropertySource(value = {"tsp_client.yaml", "file:tsp_client.yaml"}, ignoreResourceNotFound = true)
@ConfigurationProperties
public class TSPClientConfig {
public String qwer;
public List<String> strings;
public String getQwer() {
return qwer;
}
public void setQwer(String qwer) {
this.qwer = qwer;
}
public List<String> getStrings() {
return strings;
}
public void setStrings(List<String> strings) {
this.strings = strings;
}
}
有了这个,我仍然得到大小为 0 的列表。qewr 属性映射很好。
字符串上的缩进应该没问题,因为我是从 here 复制的。
那么,你能告诉我是 spring 对此有一些问题还是我在这里做错了什么?最终我需要在列表中有复杂的对象。
Spring-Boot:2.1.2.RELEASE
【问题讨论】:
-
什么重复?然后链接解决方案
-
复杂对象的映射在哪里?
标签: java spring-boot yaml configurationproperty