Skip to content
AITroveRead. Build. Understand.
Make this comfortable

Spring Boot configuration sources: test each deployment path, not a guessed order

Last updated: 30 Sept 20264 min read
tutorial
IntermediateBy AITrove Editorial

A configuration source matrix records which value reaches a typed bean when defaults, files, environment variables and command-line arguments disagree.

Download Spring source kit

Two forms of evidence

The kit has an ApplicationContextRunner test that inserts a packaged-default source and an operator source manually, then checks the bound timeout. A newer SpringApplicationBuilder test passes defaults and a command-line override through Boot startup. Both checks are narrow. The newer BootRelaySettingsTest also reads a real local temporary application.properties file. RelaySettingsProcessTest now sets real child-process environment values and reads local relative config imports. A synthetic local configtree is now checked in a child process. A deployment-mounted file and secret source remain untested.

Build a deployment matrix with one case per actual source combination: packaged file, profile-specific file, mounted file, environment variable, command-line flag and secret store. Assert the effective bean value and the source origin for a non-secret key. The CLI check is the first checked row. The manual source check is a second, different row.

Reduce configuration drift

Use one prefix and document the supported keys. A property name that changes between releases needs a migration notice and a test for the old key. Fail startup when a required setting is absent. Unknown fields require a policy: Boot binding can ignore unknown names unless the application opts into stricter behavior, so a typo may leave the default running.

Do not publish values for credentials. Verify that a secret is present and correctly shaped without returning it in an error page or health detail. A deployment-specific override deserves a real startup test in the deployment environment, not only a unit test with a MapPropertySource.

Checked source

Java
// Matrix to add outside this kit:
// packaged file × profile file × environment × CLI × mounted secret
// Assert the bound RelaySettings value for each supported combination.

Verification boundary

ConfigurationOverrideBoundaryTest.selectsAndValidatesTheEffectiveTimeout and BootRelaySettingsTest.commandLineOverridesPackagedDefaults. The excerpt is shortened or a labelled design sketch; the kit contains the checked tests.

Costs and limits

The full matrix is a plan. A manual two-source override, Boot default/CLI override, local additional file and file/CLI collision are checked. A selected review profile and missing required/optional imports are also checked. Host environment variables and mounted deployment files remain untested.

Common Mistakes

  • Do not claim a real environment-variable test from a manually inserted MapPropertySource.
  • Do not display secret values when explaining origin.
  • Do not assume a misspelled property causes startup failure by default.

Read next

Spring Boot command-line properties: test the effective value at startup, Spring Boot configuration validation: reject an unusable relay before work starts, Spring Boot property override: fail startup on the effective value, Spring Boot profiles and property precedence: test the selected environment.

Checked file and migration continuation

Continue with Spring Boot external config file: bind the value the process actually loads, Spring Boot file versus command line: assert the bound result.

Continue with checked Boot startup

Continue with Spring Boot profile files: bind only the selected environment override, Spring Boot config source priority: a builder default may lose to a packaged file.

Release boundary continuation

Continue with Spring Boot environment variables: bind the intended key, not a lookalike, Spring Boot relative config imports: resolve from the declaring file.

Checked process continuation

Continue with Spring Boot config precedence: command line beats a process variable, Spring Boot config tests: what a child JVM proves and what deployment still owes.

Checked config-data continuation

Continue with Spring Boot configtree versus environment: assert the effective value.

spring
spring-boot
configuration
Storage details