Spring Boot configuration behaviour with @ConfigurationProperties and Command Line arguments -
i seem having funny behaviour spring boot on yaml property files im trying load.
i have settings bean setup follows :
@configurationproperties(location = 'config.yml', prefix='settings') public class settings { private string path; ... }
i've explicitly told spring in config.yml file property values bind settings bean. looks this:
settings: path: /yaml_path
this works well, however, don't seem able override these values command line i.e.
java -jar my.jar --settings.path=test
the value bound settings bean still /yaml_path would've expected --settings.path=test override settings in yaml.
interestingly, i've noticed if take comment out path setting yaml file, commandline argument value of test comes through.
additionally, i've noticed if change config file config.yml application.yml , remove 'location' attribute configuration properties file gives me desired desired behaviour, means can't have multiple application.yml files in classpath breaks multi module application has configuration files throughout.
ideal world able have modules read configuration yaml files contain safe values module (i.e. module.yml) , able override these values commandline if needed. has figured out how commandline arguments passed beans way?
i have created project on git hub show case issue
https://github.com/vcetinick/spring-boot-yaml-test
running application displays logging information settings applied. i.e.
java -jar spring-boot-yaml-test-0.0.1-snapshot.jar --config.path=/test
should override settings, however, default /var/tmp displayed
additionally, when using application.yml configuration
java -jar spring-boot-yaml-test-0.0.1-snapshot.jar --app.path=/test
seems behave expected command line argument overrides value works because value defined in application.yml file.
looks locations attribute working designed, however, seems @ odds standard configuration paradigm setup spring boot (https://github.com/spring-projects/spring-boot/issues/5111). meant override settings. looks this feature may removed in future release of spring boot anyway (https://github.com/spring-projects/spring-boot/issues/5129)
Comments
Post a Comment