Skip to content

Configuration

Configuration separates deploy-time choices from application code. Spring Boot supports property files, YAML, environment variables, system properties, command-line arguments, and other sources with a defined precedence.

Cohesive binding

@ConfigurationProperties("catalog.client")
@Validated
public record CatalogClientProperties(
        @NotNull URI baseUrl,
        @NotNull Duration connectTimeout,
        @Min(1) int maximumConnections) {
}

Structured binding makes names, types, defaults, and validation reviewable. A startup failure for missing critical configuration is usually safer than a latent request-time failure.

Values such as maximumConnections are operational capacity policies, not mere syntax; select them using the pools and bounded-resources guide.

Secrets

Do not commit real credentials, embed them in images, or print them through configuration diagnostics. Obtain secrets through a deployment-provided secret mechanism, grant least privilege, rotate them, and define application behavior during rotation. Environment variables are a transport mechanism, not an automatic secret store.

Profiles

Profiles can activate related beans or configuration, but a large matrix of profile combinations becomes difficult to test. Prefer explicit typed properties for independent choices and reserve profiles for coherent modes.

Defaults and precedence

A useful default is safe and unsurprising. Document which source is intended to override it. Avoid scattering @Value strings through the codebase, and do not depend on an assumed precedence order without checking the current official reference.

Operational checklist

  • validate required values at startup;
  • express durations and sizes with typed units;
  • expose non-sensitive effective configuration when diagnostically valuable;
  • keep development conveniences from silently activating in production;
  • test configuration binding and critical profile combinations.

See Spring Boot externalized configuration.