[← Why your profile file lost](04-why-your-profile-file-lost.md) · [Index](../README.md) · [Config trees →](06-config-trees-and-configmaps.md) # 5. `spring.config.import` Transcript: [`04-import-and-multidoc.txt`](output/04-import-and-multidoc.txt). ```yaml spring: config: import: "optional:classpath:/imported.yaml" ``` ## The imported file wins This is the part that catches people, and it catches them in the direction opposite to the one they brace for: ``` effective value : from-imported-yaml 1. from-imported-yaml <- imported.yaml 2. from-application-import-yaml <- application-import.yaml (declared the import) 3. from-application-yaml <- application.yaml ``` The importing file declared the import and then lost to it. An imported document is processed *after* the document that declared it, and later documents win. `#include` semantics would give the opposite. So would treating the import as a set of defaults, which is what people usually intend when they import a shared baseline. If you import a company-wide `common.yaml` expecting your own file to override it, every key `common.yaml` sets will quietly beat yours. To get defaults-style behaviour, put your overrides somewhere that outranks config data — an environment variable or a command-line argument — or import from a *later* document in your own file so the ordering is explicit. ## Prefixes | Prefix | Meaning | |---|---| | `optional:` | do not fail if it is missing | | `file:` | a filesystem path | | `classpath:` | a classpath resource | | `configtree:` | a directory of value-per-file entries | They compose: `optional:configtree:/etc/config/`. Without `optional:`, a missing location is `ConfigDataLocationNotFoundException` at startup. That is usually what you want for a secret mount and never what you want for a developer machine. ## Where imports are legal `spring.config.import` is only honoured in config data — `application.yaml` and friends. Setting it as an environment variable or a command-line argument works too, because those are processed before config data is loaded. Setting it anywhere else does nothing. Imports are processed depth-first, and a cycle is detected and reported rather than looping.