代码之家  ›  专栏  ›  技术社区  ›  Mohammed

SpringBoot 2迁移配置属性无法将属性绑定到字符串[]

  •  0
  • Mohammed  · 技术社区  · 7 年前

    我刚从Spring boot 1.5.8迁移到2.0.0

    我解决了大多数迁移错误,但对此我一无所知:

    @Configuration
    public class LdapConfiguration {
    
        @Bean
        @ConfigurationProperties(prefix = "ldap")
        public LdapContextSource contextSource() {
            return new LdapContextSource();
        }
    
        @Bean(name = "ldapTemplate")
        public LdapTemplate ldapTemplate(ContextSource contextSource) {
            return new LdapTemplate(contextSource);
        }
    }
    

    我的自定义值(所有变量都是var env property,这就是分隔符为“\u”)的原因):

    LDAP_URLS=ldaps://ldap-url.com:636/
    

    错误:

    Description:
    
    Failed to bind properties under 'ldap.urls' to java.lang.String[]:
    
        Reason: Unable to get value for property urls
    
    Action:
    
    Update your application's configuration
    

    看起来它无法绑定我的字符串值ldap。URL到字符串[],我尝试在我的属性中使用两个值,用coma分隔。

    有什么想法吗?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Stephane Nicoll    7 年前

    由于某些原因,Spring Boot无法绑定到已克隆的阵列。我养大了 #12478 我认为这是2.0版新活页夹的回归。

    编辑:从Spring Boot 2.0.1开始,此问题现已修复