Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

Profiles in Spring Boot: Configuration, @Profile and Activation

Java
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedOct 17, 2024
UpdatedNov 16, 2026
4 min read

A profile in Spring Boot is a named group of configuration and beans that you activate for a specific environment, such as dev, test or prod. Profiles let one build artifact behave differently per environment, for example using an in-memory database locally and PostgreSQL in production, without code changes.

You activate profiles with the spring.profiles.active property, an environment variable or a command-line argument, and you mark beans with @Profile. The examples target Spring Boot 3.x.

Table of Contents

  • Profile-specific configuration files
  • Activating a profile
  • Using @Profile on beans
  • Profile groups
  • Testing with profiles
  • Best practices
  • Frequently Asked Questions
    • What is the default profile?
    • Can I activate more than one profile?
    • How do I set the profile in Docker or Kubernetes?
    • What is the difference between spring.profiles.active and spring.profiles.include?
  • Summary

Profile-specific configuration files

Spring Boot loads application.properties or application.yml first, then overlays application-{profile} files for each active profile. Values in the profile file override the defaults.

yaml
yaml
yaml

With a single multi-document YAML file you can use spring.config.activate.on-profile in each document instead. Note that spring.profiles was replaced by this property in Spring Boot 2.4.

Activating a profile

Pick whichever method suits the environment:

MethodExample
Property filespring.profiles.active=dev
Command linejava -jar app.jar --spring.profiles.active=prod
Environment variableSPRING_PROFILES_ACTIVE=prod
JVM option-Dspring.profiles.active=prod
Maven pluginmvn spring-boot:run -Dspring-boot.run.profiles=dev
Tests@ActiveProfiles("test")

If nothing is set, Spring uses the default profile. You can activate several profiles with a comma-separated list. Do not hard-code prod in a file that ships in the artifact; set it outside, in the environment.

Using @Profile on beans

@Profile includes a bean or configuration class only when a profile is active.

java

Profile expressions support ! for not, & for and, and | for or, and parentheses are required when mixing operators, for example @Profile("(dev | test) & !ci").

Profile groups

Groups, available since Spring Boot 2.4, let one profile name activate several others:

yaml

Running with production now activates production, proddb and prodmq, each loading its own application-* file.

Testing with profiles

java

The test profile files, such as application-test.yml, are loaded for that test class only. You can check the active profiles at runtime through Environment.getActiveProfiles().

Best practices

  • Keep secrets out of profile files. Read them from environment variables or a secret manager.
  • Keep the number of profiles small and meaningful. Prefer externalised configuration over a profile per customer.
  • Avoid putting business logic behind profiles, since untested combinations are a source of production-only bugs.
  • Log the active profiles at startup, which Spring Boot already does with a line like The following 1 profile is active: "prod".

Frequently Asked Questions

What is the default profile?

If no profile is active, Spring uses default. Beans annotated with @Profile("default") are created only in that case.

Can I activate more than one profile?

Yes. Use a comma-separated list, for example --spring.profiles.active=prod,metrics. Later profiles override earlier ones.

How do I set the profile in Docker or Kubernetes?

Set the SPRING_PROFILES_ACTIVE environment variable on the container.

What is the difference between spring.profiles.active and spring.profiles.include?

active selects the profiles. include adds profiles unconditionally to whatever is active, but it cannot be used inside profile-specific files since Spring Boot 2.4.

Summary

Spring Boot profiles let you vary configuration and beans per environment. Use application-{profile} files, activate them from outside the artifact with SPRING_PROFILES_ACTIVE, mark environment-specific beans with @Profile, and group related profiles with spring.profiles.group.

Share