Spring Boot
September 8, 2021

M04 Q08 Where does Spring Boot look for property file by default?

Spring Boot looks for properties in following locations:

Profile Specific

Outside of Jar:

  • application-{profile}.properties and application-{profile}.yml outside of jar in /config subdirectory
  • application-{profile}.properties and application-{profile}.yml outside of jar in current directory

Inside Jar:

  • application-{profile}.properties and application-{profile}.yml inside of jar in /config package on classpath
  • application-{profile}.properties and application-{profile}.yml inside of jar in classpath root package

Application Specific

Outside of Jar:

  • application.properties and application.yml outside of jar in /config subdirectory
  • application.properties and application.yml outside of jar in current directory

Inside Jar:

  • application.properties and application.yml inside of jar in /config package on classpath
  • application.properties and application.yml inside of jar in classpath root package

The logic behind this organization is to give you the ability to override properties in the file that is most specific. And also give you the ability easily to change the properties during the deployment without having to change the code.

You can change name of default configuration file with usage of spring.config.name property:

$ java -jar myproject.jar --spring.config.name=myproject

You can also explicitly point location of configuration file with usage of spring.config.location property:

$ java -jar myproject.jar --spring.config.location=classpath:/default.properties