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

object mapper conflict when importing springfox #890

Closed
prabhat1790 opened this Issue Aug 4, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@prabhat1790

prabhat1790 commented Aug 4, 2015

Hi All,
I am trying to configure springfox for my application and facing a issue related to _halObjectMapper bean. My application is getting one objectMapper bean from one library and one from springfox(or its dependencies) and therefore HypermediaAutoConfiguration class is unable to determine which bean to inject and throws up the exception -
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration$HypermediaConfiguration$HalObjectMapperConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.fasterxml.jackson.databind.ObjectMapper org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration$HypermediaConfiguration$HalObjectMapperConfiguration.primaryObjectMapper; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.fasterxml.jackson.databind.ObjectMapper] is defined: expected single matching bean but found 2: enginesMapper,_halObjectMapper
Is it possible to configure this injection by name in place of by type to resolve the issue

@dilipkrish

This comment has been minimized.

Member

dilipkrish commented Aug 6, 2015

You need to find where the second object mapper is coming from. Without looking at the configuration its hard to tell

@prabhat1790

This comment has been minimized.

prabhat1790 commented Aug 6, 2015

Yes I have got the second library fixed to do the autowiring by name and not type and now I am only facing issue with the HypermediaAutoConfiguration class

@dilipkrish

This comment has been minimized.

Member

dilipkrish commented Aug 15, 2015

@prabhat1790 have you found a resolution that you could perhaps share?

@dilipkrish dilipkrish added this to the 2.3.0 milestone Aug 15, 2015

@prabhat1790

This comment has been minimized.

prabhat1790 commented Aug 19, 2015

Have made two changes for the resolution, made the hateoas object mapper as the primary bean -
private static final String SPRING_HATEOAS_OBJECT_MAPPER = "_halObjectMapper";
@Autowired
@qualifier(SPRING_HATEOAS_OBJECT_MAPPER)
private ObjectMapper springHateoasObjectMapper;
@primary
@bean
@order(value=Ordered.HIGHEST_PRECEDENCE)
@DependsOn(SPRING_HATEOAS_OBJECT_MAPPER)
public ObjectMapper objectMapper() {
return springHateoasObjectMapper;
}

and set the order of the other bean to lowest precedence

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment