1. Overview

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:

  1. file:./config/
  2. file:./
  3. classpath:/config/
  4. classpath:/

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.

application.properties file inside config dir

.properties file inside config dir

2. application.properties file in the current directory

We can put application.properties file at the same location where .jar file available.

application.properties in current directory

application.properties in the current directory

3. application.properties file in classpath /config  package

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.

application.properties file inside resources-config dir

application.properties file inside resources-config dir

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:

application.properties file inside class path root

application.properties file inside classpath root

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/

3. Conclusion

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.

4. References

Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.
Yes
No

Leave a Reply

Your email address will not be published. Required fields are marked *