【问题标题】:SpringBoot 2 migration ConfigurationProperties Failed to bind property to String[]Spring Boot 2迁移@ConfigurationProperties无法将属性绑定到String []
【发布时间】:2018-08-22 21:09:57
【问题描述】:

我刚刚从 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 属性,这就是分隔符是“_”的原因):

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.urls 绑定到 String[],我尝试在我的属性中使用 2 个由逗号分隔的值。

有什么想法吗?

【问题讨论】:

  • 在 application.properties 中尝试使用 ldap.urls 而不是 LDAP_URLS
  • 所有变量都是var env属性,这就是为什么分隔符是“_”,我没有application.properties。它适用于我的所有其他价值观
  • 啊好吧!您是否尝试过阵列方式?看这里github.com/spring-projects/spring-boot/wiki/Relaxed-Binding-2.0
  • 也许你在 Spring Boot 2 中发现了一个错误:P
  • 感谢您的帮助!在打开问题之前我会在这里等待 Spring Boot 团队

标签: java spring spring-boot spring-ldap


【解决方案1】:

由于某种原因,Spring Boot 无法绑定到克隆的数组。我提出了#12478,因为我相信这是 2.0 中新活页夹的回归。

编辑:这已从 Spring Boot 2.0.1 开始修复

【讨论】:

    猜你喜欢
    • 2018-10-17
    • 2015-08-11
    • 2020-05-21
    • 1970-01-01
    • 2018-06-09
    • 1970-01-01
    • 2021-11-11
    • 2017-06-02
    • 2021-09-22
    相关资源
    最近更新 更多