Profiles in Spring Boot allow an application to load different configurations for different environments such as development, testing, staging, and production. This helps maintain a single codebase while using environment-specific settings and resources.
Consider a Spring Boot application with different database configurations:
The same application code runs in all environments while only the configuration changes.
application-dev.properties
application-test.properties
application-prod.propertiesspring.profiles.active=prod
java -jar app.jar --spring.profiles.active=prod
@Profile("dev")
@Bean
public DataSource devDataSource() {
return new H2DataSource();
}
@Profile("prod")
@Bean
public DataSource prodDataSource() {
return new MysqlDataSource();
}The application behavior changes automatically based on the active profile.
A concise interview answer is: Spring Profiles allow us to maintain different configurations for different environments such as development, testing, and production without modifying application code. This improves flexibility, simplifies deployment, and helps manage environment-specific resources efficiently.
Last updated: 11 November 2026
Previous question: Explain how Spring Boot profiles work.
Next question: What is aspect-oriented programming (AOP) in the Spring Framework?