Search code examples
spring-bootspring-cloud-configspring-config

Spring Boot 2.0.5 can not bind list of properties from spring-cloud-config server


I've run into a next situation: I've migrated my application from Spring Boot 1.5.x to Spring Boot 2.0.5.

I have the next class:

@ConfigurationProperties(prefix = "some.property")
public class Myclass {

@Getter
@Setter
private List<String> list;

}

Also I have yml config like this:

some:
  property:
    list:
      - value 1
      - value 2
      - value 3 

This config is fetched from remote spring-cloud-config server.

If I try to run application I have next exception:

org.springframework.boot.
context.properties.bind.BindException: Failed to bind properties under 
'some.property' to Myclass


Description:

Property: some.property.list[0]
Value: value 1
Origin: "some.property.list[0]" from property source "bootstrapProperties"
Reason: The elements 
[some.property.list[0],some.property.list[1],some.property.list[2]] were 
left unbound.
   Property: some.property.list[1]
Value: value 2
Origin: "some.property.list[1]" from property source "bootstrapProperties"
Reason: The elements 
[some.property.list[0],some.property.list[1],some.property.list[2]] were 
left unbound.

Property: some.property.list[2]
Value: value 3
Origin: "some.property.list[2]" from property source "bootstrapProperties"
Reason: The elements 
[some.property.list[0],some.property.list[1],some.property.list[2]] were 
left unbound.

But if I use local bootstrap.yml file not remote config server - everything is fine.

Has anybody run in to the same problem ? I really need your help.

P.S. Spring config server has version 2.0.5 too.


Solution

  • Finally I've found a root cause of the problem.

    Well, because I am not super experienced guy with Cloud Config Server the reason were hard to find. It is all about overriding property list for different profiles:

    Let's imagine you have two property files on you config server:

    application.yml

    application-dev.yml - it has higher priority, so it overrides everything that was before it.

    In application.yml I've had property like this

    some:
      property:
        list:
    

    So, this is just empty list.

    But in application-dev.yml I've had property like this:

    some:
      property:
        list:
          - value 1
          - value 2
          - value 3
    

    So, in this situation you will get error like I've mentioned above. All you need to do - fix empty list like this.

    some:
      property:
        list:
          - ""