New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'spring.config.import' placeholders can resolve from profile-specific documents when they should fail #29386
Comments
I uploaded the code to reproduce this problem here. https://github.com/tauparticle/SpringBootPropLoadingDemo |
@tauparticle https://github.com/tauparticle/SpringBootPropLoadingDemo gives a 404 for me. Can you double check the link is correct. |
@philwebb apologies. I think it was made private originally. It should work now. |
Thanks. The problem looks somewhat related to #23020. The placeholder resolver logic isn't working with contributors that have |
@tauparticle I've pushed a fix for this, but I'm afraid it's not going to allow you to import configuration in the way you're trying to do it. Placeholder resolution should have always failed when you try to reference a property in an inactive document. This was an intentional design decision that we made when we introduced I would suggest changing your YAML so that the imports are directly declared, rather than using placeholders. For example: ---
spring:
config:
activate:
on-profile: profileA
import:
- application/prod.yml
---
spring:
config:
activate:
on-profile: profileB
import:
- application/test.yml |
Thanks for the clarification @philwebb! |
Greetings Spring Boot. I ran into an unexpected results with the following setup with config loading. Let's consider we have the following
application.yml
file.And we have
application/prod.yml
with the following contents:myTestProp: testProp/prod
And
application/test.yml
with the following contents:myTestProp: testProp/test
And finally we have the following test that will activate
profileB
and assert on expected results.And we have the following test to activate both profiles
profileA
andprofileB
and assert on expected results.What I've observed is
ProfileABPropsTest
passes expectedly. The file-order profile activation picks up the override fortest.environment
inprofileA
which is then used inprofileB
to importprod.yml
as a property source.However what fails is
ProfileBPropsTest
. OnlyprofileB
is active, so we assume the default value oftest.environment=test
will causetest.yml
to be imported as a property source. Instead what we find is the value ofmyTestProp=testProp/prod
which would only happen ifprod.yml
was loaded. But as we can see by the test,test.environment=test
, so how is it that we get this property in this scenario unless the expression${test.environment}
is pulling in an incorrect value that should technically only happen ifprofileA
is activated.I cannot explain this from reading the Spring documentation. For context, I am seeing this in spring boot 2.5.x.
The text was updated successfully, but these errors were encountered: