在Spring MVC中使用Spring-Version 4.2获取“映射Mongo Converter”错误

时间:2018-07-15 14:10:13

标签: spring-mvc cors hibernate-ogm

运行 spring-mvc应用程序时,出现以下错误 数据库为 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;

这是我的具有依赖性的 pom.xml 文件

<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>

当我将 org.springframework.version 更改为4.1.5.RELEASE正常工作

但是在那种情况下,我不能使用 @CrossOrigin 注释。

或者有人告诉我如何在 org.springframework.version 4.1.5.RELEASE

中使用 @CrossOrigin

2 个答案:

答案 0 :(得分:0)

这是问题的原因:

  

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

似乎是一个依赖性问题。 mongodb库引用的是Spring核心中不再存在的方法。 spring-data-mongodb版本1.5.2可能与spring 4.2.0不兼容

答案 1 :(得分:0)

如果您使用的是 spring 4.2.0版,请使用 spring-data-mongodb 1.8.2版。 将会解决问题