javaspringspring-bootspring-boot-configuration

Externalized Configuration in Spring boot


I have a external configuration file(out side jar). I try to run and expected that value in external file will override value in internal file(application.properties in \resource\ - in jar file). I read Documentation and try this:

java -jar ccgame-1.0.jar --spring.config.location=classpath:/application.properties,file:/production.properties

This not working.

My jar file at \target\ directory and my production.properties too(at \target\)

How can I resolve my problem?


Solution

  • Starting from Spring Boot 2.0 it's possible to use property spring.config.additional-location. With this property, you can set external config file, but properties from that config will only override the corresponding ones from internal config, leaving other properties unchanged.

    More about it in docs.

    If you need to completely override the whole config, then continue to use spring.config.location property instead.