繁体   English   中英

应用 Yml 地图<String,Map<String,List<Object> &gt;&gt; 弹簧靴结构

[英]Application Yml Map<String,Map<String,List<Object>>> in spring boot structure

我有一个收藏

@Component
@ConfigurationProperties(prefix="com.ptsb.refData")
public class RefDataConfigMap {

    private Map<String,Map<String,List<RefDataResponse>>> entries;

    public Map<String, Map<String, List<RefDataResponse>>> getEntries() {
        return entries;
    }

    public void setEntries(Map<String, Map<String, List<RefDataResponse>>> entries) {
        this.entries = entries;
    }

RefDataRespone:

public class RefDataResponse {

      @JsonProperty("sourceSystem")
      private String refKeyTgtSystem = null;

      @JsonProperty("sourceSystemValue")
      private String refKeyTgtSystemValue = null;

    public String getRefKeyTgtSystem() {
        return refKeyTgtSystem;
    }

    public void setRefKeyTgtSystem(String refKeyTgtSystem) {
        this.refKeyTgtSystem = refKeyTgtSystem;
    }

    public String getRefKeyTgtSystemValue() {
        return refKeyTgtSystemValue;
    }

    public void setRefKeyTgtSystemValue(String refKeyTgtSystemValue) {
        this.refKeyTgtSystemValue = refKeyTgtSystemValue;
    }

}

我正在 application.yml 中初始化,如下所示

com:
  ptsb:
    refData:
      entries:
             GENDER:
                    Male:
                         - refKeyTgtSystem:Siebel
                           refKeyTgtSystemValue:M

当我尝试执行应用程序时出现错误。

无法将“java.lang.String”类型的属性值转换为属性“entries[GENDER][Male][0]”所需的类型“com.ptsb.ref.models.RefDataResponse”; 嵌套异常是 java.lang.IllegalStateException:无法将“java.lang.String”类型的值转换为属性“entries[GENDER][Male][0]”所需的类型“com.ptsb.ref.models.RefDataResponse”:找不到匹配的编辑器或转换策略

如何在应用程序 yml 中初始化它?

这个:

- refKeyTgtSystem:Siebel
  refKeyTgtSystemValue:M

定义一个具有单个字符串条目的序列, "refKeyTgtSystem:Siebel refKeyTgtSystemValue:M" 如有疑问,您可以使用使用 PyYAMLNimYAML (我的作品)或其他工具的在线工具来查看您的 YAML 是如何被解析的。

问题是您忘记在:字符后添加一个空格。 这是 YAML 要求的未加引号的映射键。 即便如此,您仍使用@JsonProperty来更改键的名称,因此正确的语法是:

- sourceSystem: Siebel
  sourceSystemValue: M

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM