Spring ConversionService adding Converters
While experimenting with different ways and even following spring source code in some i came across with an interesting thing.
The only way i found to use conversionService without overriding the existing converters with my custom ones was either to extend or re-implement the conversionService calling the super class's afterPropertiesSet() method to register the default converters and then add the custom ones.
But even if i was using that way, at runtime i was getting an exception that no converter was found for my specific types (e.g. from String to Logger).
That triggered my interest and i followed spring source code to find out why and i realized that spring was trying to find a custom converter registered with PropertyEditor. I am not sure why this is happening. I have to add here that my application is not using spring mvc and conversionService might somehow need to be registered and i didn't do it.
Finally, i solved the issue with registering a custom converter using Property editor. This documentation can be viewed as reference:
http://static.springsource.org/spring/docs/current/spring-framework-reference/html/validation.html
I would be very interested in knowing why Spring was not finding my registered custom converters in the conversionService's registry (or at least why spring was not looking at that registry to find the custom converters). Was i missing any configuration?
For anyone who stumbles on this now via a google search or similar 2+ years after the question was originally posted, adding converters has been made much easier through Java Config: WebMvcConfigurerAdapter
provides the addFormatters(FormatterRegistry)
method that can be used to specify additional custom converters.