The spring.profiles.active property tells Spring Boot which configuration profiles are active. Setting it to prod makes Boot load application-prod.properties or application-prod.yml on top of the base application file and enables beans annotated with @Profile("prod"). That lets one build artifact run in development, test and production with different databases, credentials and behaviour.
For production, set the profile from outside the jar, for example with the SPRING_PROFILES_ACTIVE environment variable, rather than hard-coding it in a packaged file.
Spring Boot always reads application.properties or application.yml first. For each active profile it then reads application-{profile}.properties or .yml and lets those values override the base ones. With prod active:
When several profiles are active, later ones in the list win. If you set spring.profiles.active=prod,eu, values in application-eu.properties override those in application-prod.properties.
Boot accepts the property from many sources. These are the common ones, roughly from highest to lowest priority:
| Source | Example |
|---|---|
| Command-line argument | java -jar app.jar --spring.profiles.active=prod |
| JVM system property | java -Dspring.profiles.active=prod -jar app.jar |
| Environment variable | SPRING_PROFILES_ACTIVE=prod |
| Config file | spring.profiles.active=prod in application.properties |
A quick production launch looks like this:
In a container, pass it as an environment variable:
In Kubernetes, set it under env in the container spec of your Deployment. With Maven you can also pass it while developing using ./mvnw spring-boot:run -Dspring-boot.run.profiles=prod.
Putting spring.profiles.active=prod inside the committed application.properties is a common mistake. Every developer machine and test run then starts as production. Keep the file's value empty or set it to a safe default like dev, and let the environment override it for production.
One rule to remember: you cannot set spring.profiles.active inside a profile-specific file such as application-prod.properties. Boot rejects it, because the profile is already decided by then.
Annotate beans or configuration classes with @Profile to include them only in certain environments:
The !prod expression means every profile except prod. You can also combine profiles, such as @Profile("prod & eu"). For tests, select a profile with @ActiveProfiles("test").
Since Spring Boot 2.4 you can bundle profiles into a group, so activating prod also activates related profiles:
Activating prod now loads application-proddb, application-prodmq and application-metrics as well. You can also keep several environments in one YAML file by using documents and spring.config.activate.on-profile:
The older spring.profiles key inside a document was removed in Boot 2.4 for this purpose. Use spring.config.activate.on-profile instead.
The following 1 profile is active: "prod", which helps when diagnosing wrong settings.if (profile.equals("prod")) in code. Prefer configuration properties and @Profile beans.Boot uses the default profile. You can change that default with spring.profiles.default.
Yes. Separate them with commas, for example prod,eu. Later profiles override earlier ones.
The environment variable and command-line argument take precedence over a value in application.properties.
Look at the startup log line, or inject Environment and call getActiveProfiles().
spring.profiles.active selects which application-{profile} files and @Profile beans Boot uses. Set it to prod from the environment or command line, not inside the packaged config, and keep secrets outside the repository. Use profile groups and spring.config.activate.on-profile for tidy configuration.