configuration-properties/ @ConfigurationProperties vs @Value on Spring Boot 4.1.1. The relaxed-binding matrix is generated by binding each spelling rather than transcribed, and re-checked against real processes -- the in-process probe was wrong twice before it was right. Records the three findings that came out of it: @Value does get relaxed resolution inside Spring Boot (Boot attaches ConfigurationPropertySources), the configuration processor silently stops generating metadata on JDK 23+ when declared as a plain dependency, and @Valid is not what makes nested constraints run. profiles-and-config/ Precedence, profiles, spring.config.import and config trees. /precedence reports every source holding a property in rank order with file and line, which turns "my profile file had no effect" into a two-line answer. Also pins the counterintuitive one: an imported file outranks the file that imported it. spring-aop/ Designators, proxy types, and aspects that do not fire. One advice per supported designator so the reference table is generated from real matches; all fourteen unsupported designators fed to the parser. Two corrections to the reference documentation: unsupported designators throw UnsupportedPointcutPrimitiveException (extends RuntimeException, not IllegalArgumentException), and spring-boot-starter-aop was renamed to spring-boot-starter-aspectj in Boot 4. 19 contract tests across the three modules, 15 captured transcripts, all regenerated by scripts/run-all.sh. Verified on Spring Boot 4.1.1, Spring Framework 7.0.9, JDK 25.0.4.1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gip4srpzMwjgoba6uEfbr5
59 lines
2.2 KiB
Markdown
59 lines
2.2 KiB
Markdown
[← 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.
|