You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
object mapper conflict when importing springfox #890
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
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
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
Activity
dilipkrish commentedon 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 commentedon 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 commentedon Aug 15, 2015
@prabhat1790 have you found a resolution that you could perhaps share?
prabhat1790 commentedon 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