定义yml配置中List<Map<String,String>> 类型的参数时,报如下错误。
#产品ROOT类型
product:
types:
- name: abc1
prefix: abc1
info: abc1
- name: abc 2
prefix: abc 2
nfo: abc2
Binding to target [Bindable@53982634 type = java.util.List<?>, value = 'provided', annotations = array<Annotation>[[empty]]] failed:
Property: product.types[0].name
Value: abc
Origin: class path resource [application.yml]:82:13
Reason: The elements [product.types[0].name,product.types[1].prefix,product.types[2].info] were left unbound.
Property: product.types[1].prefix
public List<Map<String, String>> types; public void setTypes(List types) { this.types = types; } 看错误信息,理解跟泛型相关,于是给定义的参数添加 泛型<Map<String,String>> 还是不行,最后发现是set方法才是关键。 public void setTypes(List<Map<String, String>> types) { this.types = types; }