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
application-{profile}.propertiesandapplication-{profile}.ymloutside of jar in /config subdirectoryapplication-{profile}.propertiesandapplication-{profile}.ymloutside of jar in current directory
application-{profile}.propertiesandapplication-{profile}.ymlinside of jar in /config package on classpathapplication-{profile}.propertiesandapplication-{profile}.ymlinside of jar in classpath root package
Application Specific
application.propertiesandapplication.ymloutside of jar in /config subdirectoryapplication.propertiesandapplication.ymloutside of jar in current directory
application.propertiesandapplication.ymlinside of jar in /config package on classpathapplication.propertiesandapplication.ymlinside 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