-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Ensure PropertySourcesPlaceholderConfigurer
uses the ConversionService
from the Environment
#34936
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
base: main
Are you sure you want to change the base?
Conversation
…n service from the Environment I noticed an issue with PropertySourcesPlaceholderConfigurer moving from spring framework 6.2.6 to 6.2.7. Basically there is a new propertyResolver being created but it is not setting the environments configured conversion service. In the context of spring boot this could cause some issues if custom converters are registered as the propertyResolver if it doesn't have a conversion service set then uses the default and would not include any registered custom converters with the environment. I don't think this PR is the exact correct fix and I didn't add any tests but this did resolve the issue with the propertyResolver having the environments conversion service. If you look at PropertySourcesPlaceholderConfigurer in spring 6.2.6 you will see that the environments conversion service is set on the propertyResolver. Signed-off-by: Michael Bazos <[email protected]>
if(this.environment instanceof ApplicationServletEnvironment) { | ||
propertyResolver.setConversionService(((ApplicationServletEnvironment) this.environment).getConversionService()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (this.environment instanceof ConfigurableEnvironment configurableEnvironment) { | |
propertyResolver.setConversionService(configurableEnvironment.getConversionService()); | |
} |
I looked into a possible fix before looking at your proposal, and I first came up with the analogous solution above.
We cannot use ApplicationServletEnvironment
here, since that class is specific to Spring Boot and Servlet deployments.
Thus, downcasting to ConfigurableEnvironment
using instanceof
pattern matching would be the correct way to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks something didn't feel right with the change I made
Hi @mbazos, Congratulations on submitting your first PR for the Spring Framework! 👍 And thanks for reporting the issue, which appears to be a regression caused by the changes made in conjunction with #34861. After having pondered it a bit more, I think your proposal (as well as the similar one I posted) may not be the best approach to restoring the original behavior in If we set the However, that was not the previous behavior. Previously, the We could consider applying a custom At this point, I will introduce tests to confirm that this is a regression, and if it's a regression I will reinstate the previous behavior (automatic conversion of values from In light of the above, I plan to decline this PR; however, I will leave it open until I have completed the aforementioned tasks. Cheers, Sam |
PropertySourcesPlaceholderConfigurer
uses the ConversionService
from the Environment
Thanks @sbrannen appreciate the thorough and prompt review. Let me know if you need anything else. |
I noticed an issue with PropertySourcesPlaceholderConfigurer moving from spring framework 6.2.6 to 6.2.7.
Basically there is a new propertyResolver being created but it is not setting the environments configured conversion service. In the context of spring boot this could cause some issues if custom converters are registered as the propertyResolver if it doesn't have a conversion service set then uses the default and would not include any registered custom converters with the environment.
I don't think this PR is the exact correct fix and I didn't add any tests but this did resolve the issue with the propertyResolver having the environments conversion service. I figured this would be the best way to show the problem and how to fix it. If I have more time I can do a proper PR but might need some guidance if the fix is not in the right place.
If you look at PropertySourcesPlaceholderConfigurer in spring 6.2.6 you will see that the environments conversion service is set on the propertyResolver.