Skip to content

object mapper conflict when importing springfox #890

Closed

Description

@prabhat1790

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

Activity

  1. dilipkrish commented on Aug 6, 2015

    @dilipkrish
    Member

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

  2. prabhat1790 commented on Aug 6, 2015

    @prabhat1790
    Author

    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

  3. dilipkrish commented on Aug 15, 2015

    @dilipkrish
    Member

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

  4. added this to the 2.3.0 milestone on Aug 15, 2015
  5. prabhat1790 commented on Aug 19, 2015

    @prabhat1790
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions