Medium15 minSpring Boot Fundamentals
UpdatedAug 5, 2026
Edit

Spring Boot Profiles

Question Variations

  • "How do Spring profiles change bean creation?"
  • "What wins when a property is defined in several sources?"
  • "Why should production secrets not live in profile YAML files?"

Why This Is Asked

Profiles test whether candidates can vary environment-specific wiring safely without scattering environment checks through application code.

Key Concepts

  • Profiles activate configuration and beans for a deployment environment.
  • Property source precedence determines the final effective value.
  • Production secrets belong in secure external configuration.
  • Tests should declare their configuration explicitly.

Question Variations

  • “How do Spring profiles change bean creation?”
  • “What wins when a property is defined in several sources?”
  • “Why should production secrets not live in profile YAML files?”

Answers by Technology

+ Add Variant
Spring BootImprove this answer ✏️

Expected Answer (Spring Boot 4.1.0 / Java 17+)

Profiles let Spring Boot activate environment-specific properties and beans without putting environment conditionals throughout business code. Use them for legitimate wiring differences, such as a local fake integration, while keeping the application contract stable. The final property value follows Spring Boot’s property-source precedence, so command-line arguments and environment variables can override packaged configuration. Supply production secrets through a secure external source rather than committing them to profile files.

Why It Matters

Clear profile boundaries prevent accidental production behavior and make deployments reproducible.

Code Example

@Configuration
@Profile("dev")
class DevelopmentConfig {
  @Bean Clock clock() { return Clock.systemUTC(); }
}

Common Mistakes

  • Using profiles for arbitrary business logic: Deployment wiring becomes application behavior.
  • Committing production secrets in YAML: Source history and build artifacts expose them.

Follow-up Questions

  • What overrides packaged properties? (Answer: Higher-precedence sources such as environment variables.)
  • Why set test profiles explicitly? (Answer: To avoid relying on a developer machine’s active configuration.)