-
Notifications
You must be signed in to change notification settings - Fork 41.2k
@ConfigurationPropertiesBinding does not apply Formatter beans #23576
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
Letting QuantityFormatter implement Converter<String, Formatter> will cause the instance not registered as a formatter anymore for the following reason: - Spring Boot's WebMvcAutoConfigurationAdapter.addFormatters(…) calls ApplicationConversionService.addBeans(…) - That in turn uses an if-*else*-cascade to register the found beans in the Formatting registry. If the bean implements Converter, it will not see the call to ….addFormatter(…) anymore. This has been filed in spring-projects/spring-boot#23576. As a workaround we now register a separate converter implementation that delegates to the formatter.
I used the if/else cascade because I was worried about beans being registered twice. The Why do you need to have the |
I got to this as follows:
I fixed that be creating a separate class implementing While this is of course fine, I think it's problematic as it's unusual that adding an interface to a type breaks the functionality plugged in for another implemented interface. The class still is a formatter but it's not considered one anymore. I was able to find out what caused this because I remembered that the beans would be routed into the If you think such an arrangement is rare (which I tend to agree with) wouldn't that also mean that your original reason to use else blocks (potential double registration) is guarding a rare case? The auto configuration arrangement currently differentiates between beans of the two relevant types and thus you apparently need to register the functionality twice. The current state requires me to register two beans that could in fact be one. |
I'd like to dig a bit more into why Internally we have I'll try and create a sample to see if I can replicate the problem. |
I can try to tweak the one I have in that direction in a couple of minutes and report back. Before you invest a lot of time in creating one from scratch. |
Some more info I could gather: Adding If you picked up formatters, what |
We'd rely on the standard |
|
Yes, I think if your servers are set to different locales then the |
I have a bean that implements
Formatter
that is supposed to also implementConverter
as I need it to be considered for application property binding as well and I can simply forward the call toconvert(…)
to theparse(…)
method of the converter.Doing that causes the instance not to be registered as
Formatter
anymore asApplicationConversionService.addBeans(…)
uses an if-else cascade to forward the registration calls. Any particular reason it does not simply use a sequence of ifs?The text was updated successfully, but these errors were encountered: