当前位置: 首页 > 知识库问答 >
问题:

Spring yaml属性java。util。LinkedHashMap无法强制转换为java。串

柳逸春
2023-03-14

我试图在Spring boot应用程序中传递Docker env变量。yml是这样的:

  security:
    saml2:
      relyingparty:
        registration:
          my-saml:
            signing:
              credentials:
                - private-key-location: classpath:HARD_PATH_TO_KEY
                  certificate-location: classpath:HARD_PATH_TO_CERT
            identityprovider:
              verification.credentials:
                - certificate-location: classpath:HARD_PATH_TO_CERT
              entity-id: MY_ID
              singlesignon:
                url: {{saml.ip.singlesignon.url}}
                sign-request: true

但是当我使用env变量

            - private-key-location: {{saml.ip.private.key}}
              certificate-location: {{saml.ip.certif.emp}}

          verification.credentials:
            - certificate-location: {{saml.ip.certif2.emp}}

我犯了这个错误:

java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.lang.String
    at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
    at org.springframework.beans.factory.config.YamlProcessor.buildFlattenedMap(YamlProcessor.java:309)
    at org.springframework.beans.factory.config.YamlProcessor.lambda$buildFlattenedMap$1(YamlProcessor.java:325)
    at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
    at org.springframework.beans.factory.config.YamlProcessor.buildFlattenedMap(YamlProcessor.java:309)
    at org.springframework.beans.factory.config.YamlProcessor.lambda$buildFlattenedMap$1(YamlProcessor.java:325)
    at java.util.Collections$SingletonMap.forEach(Collections.java:4910)

 

有什么想法吗

共有2个答案

陆飞龙
2023-03-14

如果您想要两个单独的字符串,或者凭证是一个映射,我认为应该是:

             credentials:
                 private-key-location: {{saml.ip.private.key}}
                 certificate-location: {{saml.ip.certif.emp}}

如果你想要一个数组,我认为应该是:

             credentials:
                 - private-key-location: {{saml.ip.private.key}}
                 - certificate-location: {{saml.ip.certif.emp}}
鱼意远
2023-03-14

尝试删除行开头的“-”

          private-key-location: {{saml.ip.private.key}}
          certificate-location: {{saml.ip.certif.emp}}
          ...
          certificate-location: {{saml.ip.certif2.emp}}
 类似资料: