0

I am getting the following error when I run my spring-mvc application with database as mongodb

Error creating bean with name 'mappingMongoConverter' defined in ServletContext resource [/WEB-INF/spring-config/mongodb-config.xml]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.convert.MappingMongoConverter]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.core.convert.support.ConversionServiceFactory.createDefaultConversionService()Lorg/springframework/core/convert/support/GenericConversionService;

This is my pom.xml file with dependencies

<properties>
    <org.springframework.version>4.2.0.RELEASE</org.springframework.version>
    <spring-data-mongodb.version>1.5.2.RELEASE</spring-data-mongodb.version>
    <hibernateOgmVersion>4.2.0.Final</hibernateOgmVersion>
    <jackson.version>2.2.3</jackson.version>
  </properties>

  <dependencies>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
            <version>${spring-data-mongodb.version}</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate.ogm</groupId>
        <artifactId>hibernate-ogm-mongodb</artifactId>
        <version>${hibernateOgmVersion}</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate.ogm</groupId>
        <artifactId>hibernate-ogm-core</artifactId>
        <version>${hibernateOgmVersion}</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate.ogm</groupId>
        <artifactId>hibernate-ogm-infinispan</artifactId>
        <version>${hibernateOgmVersion}</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
   </dependency>

   <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.10</version>
  </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>${jackson.version}</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>${jackson.version}</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>${jackson.version}</version>
    </dependency>


    <dependency>
        <groupId>com.thetransactioncompany</groupId>
        <artifactId>cors-filter</artifactId>
        <version>2.6</version>
    </dependency>


    <dependency>
        <groupId>com.allenru</groupId>
        <artifactId>cross-origin</artifactId>
        <version>1.0.1</version>
    </dependency>



  </dependencies>

When I change my org.springframework.version to 4.1.5.RELEASE it is working

But in that case I am not able to use @CrossOrigin annotation.

Or someone tell me how to use @CrossOrigin with org.springframework.version 4.1.5.RELEASE

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
paul po
  • 99
  • 1
  • 10

2 Answers2

0

This is the cause of the issue:

java.lang.NoSuchMethodError: org.springframework.core.convert.support.ConversionServiceFactory.createDefaultConversionService()Lorg/springframework/core/convert/support/GenericConversionService;

It seems a dependency issue. The mongodb library is referring to a method that doesn't exist anymore in spring core. Probably, spring-data-mongodb version 1.5.2 is not compatible with spring 4.2.0

Davide D'Alto
  • 7,421
  • 2
  • 16
  • 30
0

If you are using spring version 4.2.0 then use spring-data-mongodb version 1.8.2. It will solve the problem

paul po
  • 99
  • 1
  • 10