Search code examples
javaspringspring-bootspring-ldap

SpringBoot 2 migration ConfigurationProperties Failed to bind property to String[]


I just migrate from Spring boot 1.5.8 to 2.0.0

I solved most of migration errors, but I have no idea for this:

@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);
    }
}

My custom values (all variables are var env property, this is why the separator is "_"):

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

Error :

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

looks like it can't bind my string value ldap.urls to String[], I tried with 2 values in my property separated by coma.

Any idea ?


Solution

  • For some reason, Spring Boot can't bind to an array that is cloned. I've raised #12478 as I believe this is a regression in the new binder in 2.0.

    Edit: this is now fixed as of Spring Boot 2.0.1