Multiple conversion services in spring-boot

I have a download application and on one of my facades I try Autowire conversionService as follows:

 @Autowired private ConversionService conversionService; 

As a result, I get the following:

 Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.core.convert.ConversionService] is defined: expected single matching bean but found 3: mvcConversionService,defaultConversionService,integrationConversionService at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1061) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ... 16 more 

To overcome this, I added the lilke classifier:

 @Autowired @Qualifier("mvcConversionService") private ConversionService c; 

and it all works. However, all of my custom converters are automatically added to the mvcConversionService . And now I want to extend the conversionService and add another method to it, however my converters are again added to the mvcConversionService . Is there a way to tell spring-boot which conversionService use to automatically register my converters there? I do not want to manually list all the converters in the new conversionService .

+6
source share
1 answer

I had a similar problem. The problem is that you need to determine which conversion service you want to use. You can do this using XML or using the Spring Boot configuration.

I copy here part of the answer to a very similar question (the one that worked for me) and marked this question as a possible duplicate.

Take a look at the Spring documentation that you should declare a ConversionService bean. In the XML configuration, it looks like this:

 <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"> <property name="converters"> <set> <bean class="example.MyCustomConverter"/> </set> </property> </bean> 
0
source

Source: https://habr.com/ru/post/981448/


All Articles