Medium15 minSpring Boot Fundamentals
UpdatedAug 5, 2026
Edit

Spring Boot Configuration Properties

Question Variations

  • "Why prefer `@ConfigurationProperties` over scattered `@Value` fields?"
  • "How do you validate startup configuration?"
  • "How should production secrets be supplied?"

Why This Is Asked

Externalized configuration tests whether candidates can keep environment-specific values out of code while retaining a validated, discoverable contract.

Key Concepts

  • @ConfigurationProperties binds a namespaced configuration object.
  • Validation catches invalid startup configuration.
  • Profiles and environment variables select deployment values.
  • Secrets should come from secure external configuration, not source control.

Question Variations

  • “Why prefer @ConfigurationProperties over scattered @Value fields?”
  • “How do you validate startup configuration?”
  • “How should production secrets be supplied?”

Answers by Technology

+ Add Variant
Spring BootImprove this answer ✏️

Expected Answer (Spring Boot 4.1.0 / Java 17+)

Use @ConfigurationProperties to bind a coherent, namespaced configuration contract to a typed object. It is preferable to scattered @Value fields because it groups related settings, supports metadata, and can be validated at startup. Keep configuration externalized per environment and inject secrets through a managed mechanism rather than source code.

Why It Matters

Typed validated configuration turns deployment mistakes into deterministic startup failures rather than production behavior surprises.

Code Example

@ConfigurationProperties("app.mail")
@Validated
public record MailProperties(@NotBlank String host, @Min(1) int port) {}

@SpringBootApplication
@ConfigurationPropertiesScan
public class Application { }

Common Mistakes

  • Putting secrets in committed YAML: They leak through source control and logs.
  • Using unrelated @Value fields everywhere: Configuration contracts become hard to validate and discover.

Follow-up Questions

  • When does validation happen? (Answer: During property binding at application startup.)
  • Why use profiles? (Answer: To vary non-secret configuration by environment.)