SpringApplication will load properties from application.properties files in the following locations and add them to the Spring Environment:
For me the easiest way to do it, was to place a context file inside Tomcat's config folder. For example if your application is running under root path (eg. http://your_domain.com/
) you need to create a file [path_to_your_tomcat]/conf/Catalina/localhost/ROOT.xml
. If your application runs in a different path, for example http://your_domain.com/example_path
the file should be named like this [path_to_your_tomcat]/conf/Catalina/localhost/example_path.xml
. Inside this file you can specify a path to the external application.properties file that can be placed anywhere on your hard drive.
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Environment name="spring.config.location" value="file:/path/to/your/application/properties/file/" type="java.lang.String"/>
</Context>
if anyone is looking for a linux solution, This is working for us:
edit tomcat startup.sh
add:
export spring_config_location=/<YOUR_PATH>/application.properties
example:
export spring_config_location=/app/conf/application.properties