Reputation: 157
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
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
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:
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