A relative config import is resolved from the file that declares it, which can differ from the process working directory.
Spring Boot relative config imports: resolve from the declaring file
Follow the declaring file
Suppose /etc/receipt/application.properties imports optional:relay/worker.properties. The relative path belongs beneath /etc/receipt, not beneath whichever directory the Java process started in. A nested import inside relay/worker.properties uses that nested file as its own base. A file: prefix selects a fixed path instead.
This matters during packaging. A local test might run from the repository root while a container starts from /app. If the import is optional, both starts can succeed with different values. The missing optional test proves only that fallback is allowed, not that the operator file was found.
Choose failure behavior by ownership
A required deployment file should fail startup when absent. The required-import fixture covers that narrow condition. A developer-only override can be optional, but its absence should be visible through a redacted startup diagnostic. Do not make a required credential optional to quiet a bad mount.
Move the same packaged artifact between two launch directories in a release test. Inspect the bound non-secret value after each start and confirm the expected file was loaded. RelaySettingsProcessTest now checks a relative import beneath a declaring file while the child starts in another directory. A container volume remains untested.
Working sketch
spring.config.import=optional:relay/worker.properties
# In /etc/receipt/application.properties, this resolves under /etc/receipt/relay/.Verification boundary
RelaySettingsProcessTest.relativeImportUsesItsDeclaringFileOutsideTheWorkingDirectory checks a relative child-file import; RelaySettingsProcessTest now checks a second nested import.
Costs and limits
No mounted directory, container working-directory change or nested import is exercised by the Maven suite.
Common Mistakes
- Do not resolve every relative import against the shell working directory.
- Do not mistake optional startup for proof that a file loaded.
- Do not put credential contents in a config-origin diagnostic.
Read next
Spring Boot config import: fail startup when a required file is missing, Spring Boot optional config import: know which default survives, Spring Boot external config file: bind the value the process actually loads, Spring Boot config validation: separate valid syntax from a safe relay setting.
Checked process continuation
Continue with Spring Boot relative config import: change the working directory and inspect the value.
Checked config-data continuation
Continue with Spring Boot nested config imports: each file becomes the next base directory.
