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

Time:11-16

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. https://github.com/spring-projects/spring-boot/releases?page=3 It was changed by this PR: https://github.com/spring-projects/spring-boot/issues/26088

How can we add the converters instead?

CodePudding user response:

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: https://docs.spring.io/spring-boot/docs/2.5.6/reference/htmlsingle/#features.external-config.typesafe-configuration-properties.conversion

  • Related