java.lang.NoSuchMethodError: org.springframework.beans.factory.xml...setEnviro问题解决方法

今天在用IDEA和maven集成struts2和spring的时候遇到已给蛋疼的问题,google了半天也没找到答案,最后还是自己解决了。所以记录一下,如果今后有人遇到,提供一种可能的解决方案。

首先我的pom.xml文件中spring的依赖是这样的

    <properties>
        <spring.version>4.3.8.RELEASE</spring.version>
    </properties>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

乍一看,应该么啥毛病,core、web、context甚至连webmvc都上了。启动的时候却报错:

Context initialization failed
java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.XmlBeanDefinitionReader.setEnvironment(Lorg/springframework/core/env/Environment;)V
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:87)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:613)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:514)

谷歌半个小时也没找导解决方案。但估计应该是jar包版本有问题。于是点开Project里面的External Liabraries,发现spring相关的jar包版本基本都没问题,只有一个,一个jar包,spring-beans的版本竟然是3.0.5。。。坑爹。。。:
这里写图片描述

于是在pom.xml中添加:

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

再刷新下maven,发现版本对了。
这里写图片描述

再启动项目,搞定!

猜你喜欢

转载自blog.csdn.net/hfut_wowo/article/details/72457862
今日推荐