Standard precedence (lowest to highest)
- Compile-time defaults
- YAML config file (base)
- YAML config file (env-specific: dev/staging/prod)
- Environment variables
- Runtime overrides (feature flags)
Advertisement
Merge implementation
ConfigLoader loader = ConfigLoader.builder()
.withDefaults(DefaultConfig.class)
.withFile("application.yaml")
.withFile("application-" + env + ".yaml")
.withEnv()
.withFlags(flagsClient)
.build();
AppConfig cfg = loader.load(AppConfig.class);Advertisement
Deep vs shallow merge
Nested objects: deep merge (only override specified keys). Lists: usually replace, not concat.