定义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 = <?>, value = 'provided', annotations = array<Annotation>[[empty]]] failed:
Property: [0].name
Value: abc
Origin: class path resource []:82:13
Reason: The elements [[0].name,[1].prefix,[2].info] were left unbound.
Property: [1].prefix
public List<Map<String, String>> types; public void setTypes(List types) { = types; } 看错误信息,理解跟泛型相关,于是给定义的参数添加 泛型<Map<String,String>> 还是不行,最后发现是set方法才是关键。 public void setTypes(List<Map<String, String>> types) { = types; }