Spring Boot: Multiple similar ConfigurationProperties with different Prefixes

后端 未结 4 1002
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-29 07:45

I\'m using Spring Boot and have two very similar services which I\'d like to configure in my application.yml.

The configuration looks roughly like this:

4条回答
  •  清歌不尽
    2020-12-29 08:10

    Javvanos example worked perfektly, except for JavaBean Validation.

    I've had an annotation @NotNull on one of the properties:

    public class ServiceProperties {
       @NotNull
       private String url;
       private String port;
    
       // Getters & Setters
    

    }

    As a consequence, the application startup failed with following error message:

    ***************************
    APPLICATION FAILED TO START
    ***************************
    
    Description:
    
    Binding to target ch.sbb.hop.commons.infrastructure.hadoop.spark.SparkJobDeployerConfig@730d2164 failed:
    
        Property: url
        Value: null
        Reason: may not be null
    
    
    Action:
    
    Update your application's configuration
    

    After removing the annotation, the application startet up with correct property binding. In conclusion, I think there is an issue with JavaBean Validation not getting the correctly initialized instance, maybe because of missing proxy on configuration methods.

提交回复
热议问题