You can set spring_config_location environment spring_config_location point to the folder where the application.properties file is located.
In the case of Tomcat, you can do this by adding the following line to your <TOMCAT_HOME>/bin/setenv.sh file (create the file if it is missing):
export spring_config_location=/usr/local/tomcat/conf/
Place the properties file in this folder. If you have multiple applications, you can specify the name of the properties file for each application so that it is unique. For the Spring Boot application, I did it like this:
@SpringBootApplication public class MyApplication { public static void main(String[] args) { System.setProperty("spring.config.name", "my-app"); SpringApplication.run(MyApplication.class, args); } }
This will select a new name when starting from BOOT. To configure the name when deploying to Tomcat, overwrite the SpringBootServletInitializer configuration as follows:
public class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(MyApplication.class).properties("spring.config.name: my-app"); } }
Then name your properties file as: my-app.properties . Instead of the default name, Spring will look for it. You can put all the properties files of your applications in the specified folder, /usr/local/tomcat/conf/ in our example. Your external properties will take priority. See the priorities here: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
UPDATE
Starting with Spring Boot 2, the behavior of spring_config_location has changed (from the migration guide ):
Previously, he added the location to the default list, now he replaces the default location. If you relied on how this was handled earlier, you should use spring.config.additional-location instead.
Therefore, based on your use case, you should consider which of the properties to set as an environment variable. The new one should look like spring_config_additional-location in setenv.sh . Where to look for files is also described in the help documentation .