Spring Boot resolves external configuration file such as "application.properties" or "application.yml" in following order:
- classpath root
- current directory
- classpath /config package
- /config subdir of the current directory.
This is usually good for running spring boot application with executable jar (or war).
$ java -jar my-application.jar
However, when you convert your application to build a war file which gets deployed to a servlet container and want to keep the configuration file outside of the war file, the default search path doesn't work.
One solution for this is that you can specify the external config file location in your servlet container's "spring.config.location" system property.
For example, in tomcat:
"CATALINA_HOME/bin/setenv.sh"
export CATALINA_OPTS="-Dspring.config.location=file:/usr/local/myapp/application.properties"
* The value of system property is evaluated as spring resource style format.
So, if you are specifying a file outside of classpath, you need to put "file:" prefix.
So, if you are specifying a file outside of classpath, you need to put "file:" prefix.
See more detail on org.springframework.boot.context.initializer.ConfigFileApplicationContextInitializer
2 comments:
What happens if the container is shared by multiple spring boot based war files?
For an alternative solution, when the container is shared by multiple spring boot based war files, check this
http://stackoverflow.com/questions/31017064/how-to-externalize-spring-boot-application-properties-to-tomcat-lib-folder
Post a Comment