-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Add support for non-component @PropertySource discovered by @EnableConfigurationProperties #42962
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
Comments
Thanks for the suggestion, but I'm not sure that we should support this. Let's see what the rest of the team think, but my vote would be to close this issue. |
@philwebb thank you for your reply. I understand, that it might not be implemented. Maybe in this case it would be useful to mention it in the docs more explicitly. Or maybe I'm missing it. Just spent lots of time today 😃, following the docs for |
As Phil already explained, these are two completely different things. The former is binding from the environment and the latter is mutating the environment (adding a property source with whatever the annotation defines). It's really hard for us to document all the possible cases that users might consider for the application arrangement. Especially when the features are cross projects. If you want your setup to be reproducible and solid, the environment should be prepared as soon as possible. I understand the framework feature that got created before Spring Boot was a thing is tempting (“it's just an annotation”), but it has some drawbacks, see Point 2 of this section of the reference guide. My vote is to close this issue as well. |
Thanks @snicoll. I'm going to close this one. |
I agree with this being closed. Just for future reference, it reminded me of #5129 and I think it would be likely to cause similar confusion, particularly in terms of the scope of the new property source and exactly when it is applied. IMO, #24688 or something similar will be the right way to address the sort of need raised in this issue. |
According to the documentation
@PropertySource
works on@Configuration
classes. However, it would be very beneficial, if it would also work when it's not a@Configuration
(not a@Component
in general) and is referenced by@EnableConfigurationProperties
.For example, this doesn't work:
But as soon as you comment the
@EnableConfigurationProperties
in theConfig
and uncomment the@Component
in the second class, it starts working and loads properties correctly frommy.properties
file.You can find the full code here to try it out: https://github.com/bdshadow/SpringCustomProperties
I know that
AdditionalProperties
is registered as a bean byEnableConfigurationPropertiesRegistrar
. And it is a bean when explicitly annotated by@Component
. Then why is there a difference in behavior regarding the@PropertySource
?The text was updated successfully, but these errors were encountered: