Table of Contents
- 1. Overview
- 2. By default valid location of application.properties or yml file
- 1. application.properties file should be in/config subdirectory of the current directory.
- 2. application.properties file in the current directory
- 3. application.properties file in classpath /config package
- 4. application.properties file in classpath root
- 5. Customize the location of application.properties
- 3. Conclusion
- 4. References
While working with spring boot application, application.properties or application.yml contains all configuration of the application. But sometimes spring boot ignore the application.properties or yml file because of the in-current location of application.properties file. So we have explained here which are the valid location where we can place application.properties file.
We will also explain here how we can change or customize the location of application.properties file in spring boot application.
By default, Spring boot will try to find properties file at bellow four locations. Priority of considering the application.properties is defined here:
Following are the valid location for application.properties file. We can put application.properties file at any one of the following locations.
2. By default valid location of application.properties or yml file
1. application.properties file should be in
/config subdirectory of the current directory.
We can put application.properties or application.yml in
config directory. Make sure config dir and .jar file must be at same location.
2. application.properties file in the current directory
We can put application.properties file at the same location where .jar file available.
3. application.properties file in classpath
We can also place application.properties or application.yml inside classpath. When spring boot will package the application at that time resource folder will be placed at the root of application and consider inside that classpath.
4. application.properties file in classpath root
another alternative place application.properties at the root level of classpath mean we can place at the root level of the resources folder as below:
5. Customize the location of application.properties
spring boot provides an option to change or customize the location of application.properties file.
spring.config.location is command line configuration using that we can change the location of the application.propertiles file:
It means that spring boot will try to find the file from
custom-config dir where .jar file is available.
java -jar myproject.jar --spring.config.location=file:./custom-config/
In this article, we learned that what should be the possible location where we can place that application.properties file and we can also customize or change the location of file based on our requirements.