Load application.properties outside jar

Viewed 5915

How can I set application.properties in SpringBoot outside .jar? I would link to this file and load properties from code.

1 Answers

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

Related