0

I am trying to load an array from application.properties in a Spring boot 2.4 application whereby the array is distributed across multiple property files.

  1. application.properties
spring.cloud.routes[0].id=1
spring.cloud.routes[0].name=ONE
spring.cloud.routes[1].id=2
spring.cloud.routes[1].name=TWO
spring.config.import=one.properties
  1. one.properties
spring.cloud.routes[2].id=3
spring.cloud.routes[2].name=THREE
spring.cloud.routes[3].id=4
spring.cloud.routes[3].name=FOUR
  1. Java Beans
    @Getter
    @Setter
    public class Route {
        private String id;
        private String name;
    }
    
    @Getter
    @Setter
    @ConfigurationProperties(prefix = "spring.cloud")
    @Component
    public class Routes {
        private List<Route> routes;
    }

    

On starting application, I am getting below error -

***************************
APPLICATION FAILED TO START
***************************

Description:

Binding to target [Bindable@1591271 type = java.util.List<Route>, value = 'provided', annotations = array<Annotation>[[empty]]] failed:

    Property: spring.cloud.routes[2].id
    Value: 3
    Origin: class path resource [one.properties] - 1:27
    Reason: The elements [spring.cloud.routes[2].id,spring.cloud.routes[2].name,spring.cloud.routes[3].id,spring.cloud.routes[3].name] were left unbound.
    Property: spring.cloud.routes[2].name
    Value: THREE
    Origin: class path resource [one.properties] - 2:29
    Reason: The elements [spring.cloud.routes[2].id,spring.cloud.routes[2].name,spring.cloud.routes[3].id,spring.cloud.routes[3].name] were left unbound.
    Property: spring.cloud.routes[3].id
    Value: 4
    Origin: class path resource [one.properties] - 3:27
    Reason: The elements [spring.cloud.routes[2].id,spring.cloud.routes[2].name,spring.cloud.routes[3].id,spring.cloud.routes[3].name] were left unbound.
    Property: spring.cloud.routes[3].name
    Value: FOUR
    Origin: class path resource [one.properties] - 4:29
    Reason: The elements [spring.cloud.routes[2].id,spring.cloud.routes[2].name,spring.cloud.routes[3].id,spring.cloud.routes[3].name] were left unbound.

Action:

Update your application's configuration

Is there any way to make this work without having to explicitly mention one.properties file (and any other additional files besides application.properties file) in java annotations?

Regards
Jacob

dariosicily
  • 2,691
  • 2
  • 7
  • 14
Jacob
  • 188
  • 1
  • 13

0 Answers0