Rename file in Spring Boot Application

1. Overview

By default, our Spring Boot application loads the external properties from the application properties file. This is normally available in our project resources folder. We can modify the name of application properties file, if required, even though it is a good convention to follow.

In this article, we’ll review various options to load the external properties file with a different name.

2. Setup

Once we create a Spring Boot project,

  • Let’s delete the file from the resources folder of our project.
  • Then, let’s create a file in the resources folder of our project. We’ll provide all our application configurations in this properties file. property holds the name of our properties file in the Spring Boot application.

Therefore, we’ll set our properties file as the value for this property using various options.

3. Passing Property during Startup

First, let’s pass our properties file name as an argument to the property while starting the application:

java -jar SpringBootRenameAppProperties-0.0.1-SNAPSHOT.jar

4. Environment Variable

In this section, let’s provide the new properties file name to the SPRING_CONFIG_NAME environment variable. Then, we can start the application from the command line:

set SPRING_CONFIG_NAME= customapp
java -jar SpringBootRenameAppProperties-0.0.1-SNAPSHOT.jar

5. System Property

Next, let’s set the configuration file name as the System Property before starting our Spring Boot application.

We’ll use as property key and our configuration file name as the value:

public static void main(String[] args) {
    System.setProperty("", "customapp");, args);

6. Application Property

Finally, let’s pass our configuration file name as a value to property while creating our Spring Boot application:

public static void main(String[] args) {
    new SpringApplicationBuilder(SpringBootRenameAppPropertiesApplication.class)

7. Conclusion

We reviewed various way to rename application properties file of our Spring Boot project. We can choose any one of these options to rename the file. Just note that, in all the cases we never added .properties to the file name. The framework appends it automatically to end of the file name. So if we pass as properties file name, then the application will be searching for

The code examples from this article are available on GitHub.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s