严重:在maven-webapp项目上为servlet [mvc-spring]错误分配异常

时间:2018-03-16 06:29:41

标签: java spring maven spring-mvc

我正在尝试运行maven Web应用程序项目并获取错误我已经创建了spring-servlet.xml文件和web.xml。如果我没有使用maven依赖项,那么同一项目正在运行。

    SEVERE: Allocate exception for servlet [mvc-spring]
    java.lang.NoSuchMethodError: org.springframework.context.support.AbstractApplicationContext.clearResourceCaches()V
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:878)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552)
        at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:676)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:642)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:690)
        at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:558)
        at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:499)
        at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:172)
        at javax.servlet.GenericServlet.init(GenericServlet.java:158)
        at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1174)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1090)
        at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:770)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:417)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:754)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1376)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Unknown Source)

HelloWorldController.java类

package com.javatpoint;  
import org.springframework.stereotype.Controller;  
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;  
@Controller  
public class HelloWorldController {  
    @RequestMapping(value="/hello")
    @ResponseBody
    public String sayHello() {
        return "Hello World";

    } 
} 

1 个答案:

答案 0 :(得分:0)

The maven dependency to struts2-spring-plugin : 2.3.24.1 includes a dependency on spring-web : 3.0.5.RELEASE which includes in turn a dependency on spring-beans : 3.0.5.RELEASE.

So, spring-beans : 3.0.5.RELEASE was the reference used for the org.springframework.beans.support.ResourceEditorRegistrar class, which was not compatible with the rest of spring 4.2.2.RELEASE.

I included the dependency on spring-beans : 4.2.2.RELEASE on top of my hierarchy i.e. on the pom.xml file as

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>4.2.2.RELEASE</version>
</dependency>
 the spring-beans-4.2.2.RELEASE.jar file is included in the Maven dependencies.