Profiles
One program — different environments
Local startup, a test environment, and production often require different settings. Service addresses, logging parameters, infrastructure, and sometimes the set of technical beans change. Spring Profiles let configuration become active only for the selected environment or scenario.
spring.profiles.active=dev
You can create separate configuration files for a profile,
for example application-dev.properties and application-prod.properties.
Shared values stay in the main configuration, while the profile overrides only
what is actually different.
A profile can control beans too
@Configuration
@Profile("dev")
class DevConfiguration {
@Bean
DemoDataLoader demoDataLoader() {
return new DemoDataLoader();
}
}
This configuration will be active only with the dev profile.
That is useful for infrastructure differences between environments, such as
local stubs or loading demo data.
A profile is not a universal feature toggle.
If a business feature must be enabled and disabled independently during operation,
a separate configuration property usually expresses that intent more clearly.
Check yourself
Exercise review
The mentor knows the solution and will help you reach it independently
Sign in to use the Mentor
The Mentor uses the current exercise and your conversation history.
Sign in
Review the key nuances and the answer after making your own attempt.
Sign in to view the solution
The solution and explanation are available after signing in.
Sign in