Configuring an active profile in Spring Boot via Maven allows you to control environment-specific settings during the build or run phase. It helps in managing different configurations like development, testing, and production without changing the code.
- Enables switching between environments using Maven commands
- Helps manage separate configuration files like application-dev.properties and application-prod.properties
Profiles in Spring Boot
Spring Boot profiles allow you to manage different configurations for various environments. They help customize application behavior without modifying the code.
- Separate configurations for dev, test, and production
- Control features using active profiles
- Use environment-specific property files
1. Spring Boot Profiles
Create separate property files for each profile such as the application-dev.properties and application-prod.properties and it can specify the profile-specific configurations of the application.
application-dev.properties:
greeting.message=Hello (Development)
application-prod.properties:
greeting.message=Hello (Production)
2. Maven Profiles
Maven Profiles provides the mechanism to customize the build configurations based on the different conditions or requirements. With Maven profiles, It defines different sets of dependencies, plugins, properties, and other build settings. It allows us to tailor the build process for specific scenarios.
Maven Profiles:
Define the Maven profiles in the pom.xml file and it can specify the activation criteria and configuration of the Spring application.
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring.profiles.active>dev</spring.profiles.active>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<spring.profiles.active>prod</spring.profiles.active>
</properties>
</profile>
</profiles>
Steps to Configure Active Profile in Spring Boot via Maven
Now, we will develop a simple Spring project that can configure the active profile of the Spring application.
Step 1: Create Project
We will create a spring project using Spring STS IDE by adding below mentioned dependencies to the project.
Dependencies:
- Spring Web
- Lombok
- Spring Dev Tools
Once the Spring project has created, the file structure of the project will look like the image below.

Step 2: Configure Active Profile
Open the pom.xml and put the below code for the configure active profiles in the Spring Boot application.
<profiles>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<activatedProperties>prod</activatedProperties>
</properties>
</profile>
</profiles>
Step 3: Application.properties
Open the application.properties file and put the below code the profiles configuration.
spring.application.name=spring-profiles-demo spring.profiles.active=dev
Step 4: application-dev.properties
Open the application-dev.properties file and put the below code the development configuration of the application.
greeting.message=Hello (Development)
Step 5: application-prod.properties
Open the application-prod.properties file and put the below code the production configuration of the application.
greeting.message=Hello (Production)
Step 6: GreetingsMessage Class.
Create the new java class named as GreetingsMessage.
GreetingsMessage.java
package org.example.springprofilesdemo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service
public class GreetingsMessage {
// Injecting greeting.message property value from application.properties
@Value("${greeting.message}")
private String greetingMessage;
// Method to greet the user with the configured message
public String greetUser(String name) {
return greetingMessage + " " + name + "!";
}
}
Step 7: GreetingsController
Create a new java class named as GreetingsController.
GreetingsController.java
package org.example.springprofilesdemo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GreetingsController {
// Autowiring GreetingsMessage bean
@Autowired
private GreetingsMessage greetingsService;
// Mapping GET requests to /greet/{name}
@GetMapping("/greet/{name}")
public String greet(@PathVariable String name) {
// Invoking the greetUser method of GreetingsMessage bean
return greetingsService.greetUser(name);
}
}
Step 8: Main Class
Open the main class file and write the below code.
package org.example.springprofilesdemo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringProfilesDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringProfilesDemoApplication.class, args);
}
}
Step 9: Run the application
If runs successfully, then the run the application at port 8080. Refer the below image for the better understanding.

Output:
GET http://localhost:8080/greet/mahesh

Set the production of the application properties of the application.
Open application.properties change the profile.
spring.application.name=spring-profiles-demo spring.profiles.active=prod
Again the run the application:

Output:
GET http://localhost:8080/greet/syam

If we follow the above steps, then we can successfully configure the active profiles in the Spring Boot application.