Puskin
Puskin

Reputation: 157

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?

Upvotes: 1

Views: 3841

Answers (2)

amseager
amseager

Reputation: 6391

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.

Upvotes: 5

Umesh Sanwal
Umesh Sanwal

Reputation: 777

By convention, Spring Boot looks for an externalized configuration file – application.properties or application.yml – in 4 predetermined locations in the following order of precedence:

  1. /config subdirectory of the current directory
  2. The current directory
  3. Classpath /config package
  4. The classpath root

You can place your application.properties in any of the 4 locations without needing to give the location of application.properties while executing the jar. If you want to given any other custom location , then you will have to provide the path of the config location while executing the jar:

java -jar -Dspring.config.location=<path-to-file> myProject.jar

Source: https://www.baeldung.com/spring-properties-file-outside-jar

Upvotes: 0

Related Questions