• spring 整合mongodb报NoSuchMethodError错误


    刚开始通过网上查到相关的资料进行了一些配置,参考链接:http://www.open-open.com/lib/view/open1454374782167.html

    maven的dependencies如下:

    <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</artifactId>
          <version>4.2.3.RELEASE</version>
          <exclusions>
            <exclusion>
              <groupId>commons-logging</groupId>
              <artifactId>commons-logging</artifactId>
            </exclusion>
          </exclusions>
          <type>jar</type>
          <scope>compile</scope>
    </dependency>
    <dependency>
          <groupId>org.springframework.data</groupId>
          <artifactId>spring-data-mongodb</artifactId>
          <version>1.8.2.RELEASE</version>
    </dependency>

    spring-mongo.xml

    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:p="http://www.springframework.org/schema/p"
           xmlns:mongo="http://www.springframework.org/schema/data/mongo"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/data/repository
                http://www.springframework.org/schema/data/repository/spring-repository-1.5.xsd
                http://www.springframework.org/schema/data/mongo
                http://www.springframework.org/schema/data/mongo/spring-mongo-1.5.xsd
                http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context.xsd
               ">
    <mongo:db-factory id="mongoDbFactory" host="127.0.0.1" port="27017" dbname="webusi" />
    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" /> </bean> </beans>

    测试后一直提示,mongoTemplate创建时报错:

    Error creating bean with name 'mongoTemplate' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.data.mongodb.core.MongoTemplate]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError

    后来重新调整了spring-core的版本为4.1.3.RELEASE后,就ok了,难道真是版本不兼容的问题??

    再次将spring-core版本调整为4.0.6,居然又不报错了,真是够诡异的。。。

  • 相关阅读:
    MVC提交时验证
    远程计划任务管理
    教你一步一步部署.net免费空间OpenShift系列之四------绑定域名、使用CDN加速
    启用IIS7报错功能
    教你一步一步部署.net免费空间OpenShift系列之三------上传ASP.net程序
    教你一步一步部署.net免费空间OpenShift系列之二------创建应用
    Spring SimpleJdbcOperations 批量更新
    c#获取已安装的所有NET版本
    (转载)数据库效率提高的方案
    linux两台服务器之间文件/文件夹拷贝
  • 原文地址:https://www.cnblogs.com/zhuxiangguo/p/5934949.html
Copyright © 2020-2023  润新知