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.
- 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:
for example, if you have a jar file name myapp-exec.jar as follows:
Then ,you can put the application.properties file in the following locations:
4. Custom application.properties file locations
If you want to put your application.properties file in a custom directory, for example:
You can use the spring.config.location option to specify the customized location of your application.properties file:
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)
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.