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

Spring Boot nested config imports: each file becomes the next base directory

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

A relative import declared inside an imported Spring Boot file resolves beside that imported file.

Download Spring source kit

Follow all three files

The checked child starts from a launch directory, but its additional config location points to config/application.properties. That file imports relay/worker.properties. The worker file imports overrides/late.properties. The final file lives at config/relay/overrides/late.properties and sets relay.batch-size to 37. The child reports batch 37 and keeps the one-second timeout from the first file. The one-hop test stops at worker.properties; this test adds the second hop.

Each file owns its own relative path. Resolving overrides/late.properties from the process working directory, or even from the first application.properties, would pick the wrong location. The test checks the effective bean value, not just whether every filename exists.

Check precedence and failure separately

In this fixture the later imported batch value replaces 17 from the worker file and 11 from application.properties. The one-second timeout remains because neither imported file defines it. The missing-hop case proves a required second import stops startup instead of falling back silently.

This is a local temporary-file chain in one child JVM. It does not test a Kubernetes volume, filesystem permission change or a config file replaced during startup.

Checked source

properties
// config/application.properties
relay.batch-size=11
relay.timeout=1s
spring.config.import=relay/worker.properties
// config/relay/worker.properties
relay.batch-size=17
spring.config.import=overrides/late.properties
// config/relay/overrides/late.properties
relay.batch-size=37

Verification boundary

RelaySettingsProcessTest.secondRelativeImportUsesTheIntermediateFilesDirectory. The full fixture is in the downloadable source kit.

Common Mistakes

  • Do not resolve every relative import from application.properties.
  • Do not use the launch directory as the base for an import declared in a file.
  • Do not call this temporary-file chain a container mount test.

Read next

Spring Boot relative config imports: resolve from the declaring file, Spring Boot relative config import: change the working directory and inspect the value, Spring Boot nested import failure: a missing second hop must stop startup, Spring Boot configuration sources: test each deployment path, not a guessed order.

spring
configuration
testing
Storage details