yml 对 List
类型配置
1 test: 2 list: 3 - aaa 4 - bbb 5 - ccc
直接使用
@Value("${test.list}")
private List<String> testList;
会报一下错误:
java.lang.IllegalArgumentException: Could not resolve placeholder 'test.list' in value "${test.list}"
正确配置:
1 @Configuration 2 @ConfigurationProperties("test") 3 public class TestListConfig { 4 private List<String> list; 5 6 public List<String> getList() { 7 return list; 8 } 9 10 public void setList(List<String> list) { 11 this.list = list; 12 } 13 }
若:set
private Set<Short> parentId;
TestListConfig 使用注入的形式调用