1. Introduction

This article would demo the default locations of application.properties file in spring boot application, and demo how to use custom locations to put the file in.

2. Environments

  • SpringBoot 1.x and 2.x

3. Four default locations you can put your application.properties outside jars

By default, springboot application would search by the following order to locate your application.properties:

  • file:./config/
  • file:./
  • classpath:/config/
  • classpath:/

for example, if you have a jar file name myapp-exec.jar as follows:

  • myapp-exec.jar

Then ,you can put the application.properties file in the following locations:

  • myapp-exec.jar
  • application.properties

or this:

  • myapp-exec.jar
  • config
    • application.properties

4. Custom application.properties file locations

If you want to put your application.properties file in a custom directory, for example:

  • myapp-exec.jar
  • conf
    • application.properties

You can use the spring.config.location option to specify the customized location of your application.properties file:

java -jar myapp-exec.jar --spring.config.location=file:./conf/

Notice the ‘/’ in the spring.config.location, according to spring documents:

If spring.config.location contains directories (as opposed to files), they should end in / (and, at runtime, be appended with the names generated from spring.config.name before being loaded, including profile-specific file names)

5. Summary

Although springboot allows to define your custom location of application.properties file, you’d better use the default location for better understanding and communication in the team.