By default, Spring Boot will look for your externalized properties in a file named application.properties located in one of the following folders :

  • classpath root
  • in the package /config in classpath
  • in the current directory
  • /config subdirectory of the current directory

You may want to use an externalized properties file in your Spring Boot application with a different name.  This tutorial will show 3 different ways to rename application.properties in Spring boot.

Consider we want to rename application.properties to conf.properties

Command line arguments

The first way to rename application.properties in Spring boot is by using the command line argument -- spring.config.name={YOUR_FILE_NAME}. Below an example :

If you are using Eclipse, below the steps to follow :

  • Right-Click on your Main class, Run As ->  Run configurations…
  • Go to Arguments tab
  • And in Program arguments region past : --spring.config.name=conf
  • Click Apply and then Run

Now Spring Boot will look for a file named conf.properties located in classpath root, in the package /config in classpath, in the current directory or in /config subdirectory of the current directory.

Environment variable

 You can set the name of your externalized properties file in the SPRING_CONFIG_NAME environment variable as below :

If you work with eclipse and you set the SPRING_CONFIG_NAME as a global system environment variable, you need to restart your IDE.

Programmatically

You can rename the Spring Boot properties file programmatically as below :

References