我无法从application.yml文件加载spring boot配置 以下是Yaml内容, application.yml
limits:
limitList:
-
api: test1
-
api: test2
限制班级
@Configuration
@ConfigurationProperties(prefix = "limits")
public class Limits {
List<Limit> limitList = new ArrayList<>();
public Limits() {
super();
}
public Limits(List<Limit> limitList) {
super();
this.limitList = limitList;
}
public List<Limit> getLimitList() {
return limitList;
}
public void setLimitList(List<Limit> limitList) {
this.limitList = limitList;
}
public class Limit {
String api;
public Limit() {
}
public Limit(String api) {
super();
this.api = api;
}
public String getApi() {
return api;
}
public void setApi(String api) {
this.api = api;
}
}
@PostConstruct
void print() {
for (Limit limit : limitList) {
System.out.println("Printing----->"+ limit.api.toLowerCase() );
}
}
}
出现以下错误,
无法将“ limits.limit-list”下的属性绑定到 java.util.List:
原因:无法将“ limits.limit-list”下的属性绑定到 java.util.List
操作:
更新您的应用程序配置
我在这里错过了什么吗?我已经在线检查了yml的格式,对我来说还可以。