How to add converters when ApplicationConversionService.getSharedInstance() is no longer modifiable?



I’m in the process of upgrading spring boot from 2.4.2 to 2.5.6.
In our code we have been using ApplicationConversionService.getSharedInstance().addConverter() to add our custom converters. It puzzles me a bit that this is mentioned as a "New feature" rather than a breaking change for Spring boot 2.5.0-RC1, see the top mention here.
It was changed by this PR:

How can we add the converters instead?


You need to provide the converter as a bean and annotate the bean definition with @ConfigurationPropertiesBinding. The simplest way to do so is probably to annotate the converter class with @Component and @ConfigurationPropertiesBinding.

See also this part of the reference documentation:

Answered By – Henning

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More