What are Spring Profiles and how do you use them?

Spring Profiles are a feature that allows different configurations and beans to be loaded for different environments such as Development, Testing, and Production. They help manage environment-specific settings without changing the application code.

Key Points

Example

A development environment may use an in-memory database, while a production environment uses a MySQL or PostgreSQL database. Spring Profiles allow the appropriate configuration to be loaded automatically.

@Configuration
@Profile("dev")
public class DevConfig {
}

@Configuration
@Profile("prod")
public class ProdConfig {
}

application.properties

spring.profiles.active=dev

Interview Tip

A concise interview answer is

Spring Profiles are used to manage environment-specific configurations. By using the @Profile annotation, we can define different beans and settings for environments such as development, testing, and production, and Spring loads only the configuration associated with the active profile.

Last updated: 16 July 2026

Previous question: How does the prototype scope work in Spring?

Next question: What is Spring WebFlux and how is it different from Spring MVC?

More Spring Framework - Level I interview questions

All Spring Framework - Level I questions