Profiles

Basic Spring
≈ 1 min read

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.