我正在尝试映射存储在application.yml文件中的以下配置
agents:
ongo:
mappings:
- scopeName: email
mapping: [mail, test1, test2, test3, test4]
- scopeName: phoneNumber
mapping: [phoneNumber, workPhoneNumber, personalPhoneNumber]
我创建了一个名为AgentConfiguration的类,它看起来像:
public class AgentConfiguration {
private Map<String, List<MyClass>> mappings;
public Map<String, List<MyClass>> getMappings() {
return mappings;
}
public void setMappings(Map<String, List<MyClass>> mappings) {
this.mappings = mappings;
}
public class MyClass {
private String scopeName;
private List<String> mapping;
public String getScopeName() {
return scopeName;
}
public void setScopeName(String scopeName) {
this.scopeName = scopeName;
}
public List<String> getMapping() {
return mapping;
}
public void setMapping(List<String> mapping) {
this.mapping = mapping;
}
}
}
所以,当我运行以下代码时: AgentConfiguration agent = new AgentConfiguration();
然后我评估“agent.getMapptins()”它看起来像:
但如果我使用了 “Map&lt; String,Object&gt;” 代替 “Map&lt; String,List&lt; MyClass&gt;&gt; mappings”将返回以下代码
那么为什么当我使用MyClass时它不会绑定application.yml文件中的任何内容?
答案 0 :(得分:0)
好的,我已经想出了怎么做。
我更改了AgentConfiguration类:
public class AgentConfiguration {
private List<MyClass> mappings;
public List<MyClass> getMappings() {
return mappings;
}
public void setMappings(List<MyClass> mappings) {
this.mappings = mappings;
}
static public class MyClass{
private String scopeName;
private List<String> mapping;
public AgentConfigScope() {
}
public String getScopeName() {
return scopeName;
}
public void setScopeName(String scopeName) {
this.scopeName = scopeName;
}
public List<String> getMapping() {
return mapping;
}
public void setMapping(List<String> mapping) {
this.mapping = mapping;
}
}
}
另外,请记住内部类应该是静态的,同事告诉我这是由于Spring代理限制......或类似的东西。 Spring中的AOP仅适用于公共方法。
祝你有愉快的一天!