Spring profiles give you a way to segregate parts of your application configuration and make them available only in specific environments. AnyDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/spring-projects/spring-boot/llms.txt
Use this file to discover all available pages before exploring further.
@Component, @Configuration, or @ConfigurationProperties class can be marked with @Profile to restrict when it is loaded. Pair profiles with profile-specific property files to manage environment differences — database URLs, feature flags, logging levels — without changing application code.
Marking beans with @Profile
Annotate a component or configuration class with@Profile to make it conditional on one or more active profiles:
When
@ConfigurationProperties beans are registered through @EnableConfigurationProperties rather than scanning, place the @Profile annotation on the @Configuration class that holds @EnableConfigurationProperties, not on the @ConfigurationProperties class itself.Activating profiles
Via application.properties or application.yaml
Via the command line
Programmatically
CallSpringApplication.setAdditionalProfiles(...) before the application runs. This adds profiles on top of any already configured through properties:
ConfigurableEnvironment interface on an already-running context.
Default profile
When no profile is explicitly active, Spring Boot enables thedefault profile. Properties defined in application-default.properties (or application-default.yaml) are loaded automatically in this case.
You can change the name of the default profile:
Profile-specific property files
Spring Boot automatically loadsapplication-{profile}.properties (or .yaml) variants alongside the base application.properties. Profile-specific files always override the non-specific file.
application-live.properties override those in application-prod.properties.
Adding profiles without replacing
Usespring.profiles.include to add profiles on top of the ones already activated, rather than replacing them:
common and local are always active, regardless of which profile is set via --spring.profiles.active.
Profile groups
When fine-grained profiles become cumbersome to manage, use profile groups to define a logical name for a set of related profiles:production automatically activates proddb and prodmq:
Profile validation
By default, profile names may contain letters, numbers, and the characters-, _, ., +, @, and must start and end with a letter or number. If you need more flexible names, disable validation:
Profile-specific Logback configuration
Inlogback-spring.xml, use the <springProfile> tag to include or exclude sections based on active profiles:
logback-spring.xml, not logback.xml, because standard Logback configuration files are loaded before Spring can provide profile information.