Clarify precedence between yml and properties files on the same level #25121
Labels
status: superseded
An issue that has been superseded by another
type: documentation
A documentation update
In 4.2. Externalized Configuration (Spring Boot 2.4.2) it states that
However, what is unclear is which config values wins if you have both
application.yml
andapplication.properties
on the same level. We'd like to use Variant 1 (see below), which seems to work, but relies on undocumented behavior that could easily change, so it would be great if the precedence handling could be added to the docs and checked with tests, if that is not already the case.Context:
In SB <2.4 we used:
src/main/application.yml
to store profilessrc/main/application-default.properties
to setspring.profiles.include=stage-workstation
to activate a profile if nothing was activated via ENV/systemproperty. (We used the properties file as this key is invalid in yml, but using this file makes it also easy to override for test)src/test/application-default.properties
to setspring.profiles.include=stage-workstation, test
to activate the test profilesrc/main/application-test.yml
with profile in the name to avoid overriding theapplication.yml
For SB 2.4.x
We are evaluating two solutions
Variant 1
src/main/application.yml
to store profiles and usespring.profiles.group.default=stage-workstation
src/test/application.properties
to setspring.profiles.group.default=stage-workstation,test
to activate the test profile and use properties instead of yml to avoid overriding theapplication.yml
src/main/application-test.yml
with profile in the name to avoid overriding theapplication.yml
Variant 2
src/main/application.yml
to store profiles and usespring.profiles.group.default=stage-workstation
src/test/application.yml
that usesspring.config.import=file:${user.dir}/src/main/resources/application.yml
and overrides thespring.profiles.group.default=stage-workstation,test
(IMHO it is rather brittle to rely on${user.dir}
to be set to the correct location)The text was updated successfully, but these errors were encountered: