How to let your spring boot pick up external property file

You may already see that ./config/ can override the default spring boot settings. But when you deploy your app to tomcat and with many other web app together, then you need to have unique properties files foe each app and also make external property file be picked up by web app.

So let us do something like this:

  1. Change in your java main code to let your app use a unique properties file instead of
public class MyApplication {

    public static void main(String[] args) {
        System.setProperty("", "myapp");, args);

For war version of tomcat:

public class ServletInitializer extends SpringBootServletInitializer {

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MyApplication.class).properties(" myapp");


Then name your properties file like:, instead of the default name.

2. Now let us also enable the external property file to override the default

in Spring boot, it is just ./config/

For tomcat version, we need to add env variable to do this. Set a spring_config_location environment variable pointing to the folder that contains your file. In the case of Tomcat you can do this by adding the following line to your <TOMCAT_HOME>/bin/ file (create the file if missing):

export spring_config_location=<TOMCAT_HOME>/conf/

Place the properties file in that folder <TOMCAT_HOME>/conf/.

So every app will looking into the conf folder to look for their unique properties file to load.


Refer to: