0

I'm trying to configure my Spring application.

I have in /src/main/resources my file application.yml. In my main class there is no @PropertySource annotation (but I tried also using that).

I also have another file on my Windows (/c/Programs/application.yml) that has similar content (some values are overriden).

I have to run application with following cmd call (my organization doesn't want me to use another call, because it part of CI/CD standard process):

java -Dspring.config.location=classpath:/application.yml,/c/Programs/application.yml -jar app.jar

My /src/main/resurces/application.yml file is included with .jar after building app. Running app with cmd above uses keys from resources, not from second file.

As I gathered from few hours of trying to solve this:

  1. with two files spring.config.location, second one overrides values from first one,
  2. files should be separated by comma,
  3. I don't have to use spring.config.name, when I specify single file (not directory).

What is the problem with my configuration? How can I override file from resources with external file?

franiis
  • 1,378
  • 1
  • 18
  • 33
  • see https://stackoverflow.com/questions/25855795/spring-boot-and-multiple-external-configuration-files – Ori Marko Oct 22 '19 at 10:46
  • @user7294900 Thank you - I found there information about multiple files, but I wasn't able to use it in my project. – franiis Oct 22 '19 at 10:49
  • Try `java -Dspring.config.location=classpath/application.yml,file:c/Programs/application.yml` – Ori Marko Oct 22 '19 at 10:55
  • It still uses `classpath:/application.yml`, as default properties file. – franiis Oct 22 '19 at 10:58
  • Use `spring.config.additional-location=file:/c:/programs/` Spring Boot will load an `application.yml` from that location automatically. – M. Deinum Oct 24 '19 at 17:05
  • @M.Deinum But my organization won't allow me to change `java -jar` call. I'm looking for ways to prepare my project to work with that call (if that's posiible) – franiis Oct 25 '19 at 04:54
  • You can but you shouldn't. As you will loose the benefit of using profile based loading it will then only load those 2 files and nothing profile specific anymore. I strongly suggest to follow the best practices as laid out in the spring boot reference guide. – M. Deinum Oct 25 '19 at 07:12

0 Answers0