运行简单的Spring应用程序时出现异常

时间:2016-03-28 12:20:01

标签: java spring spring-mvc

尝试运行简单的Spring MVC应用程序时会抛出异常。

的web.xml

<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>FirstSpringMVCProject</display-name>

<servlet>
  <servlet-name>spring-dispatcher</servlet-name>
  <servlet-class>
     org.springframework.web.servlet.DispatcherServlet
  </servlet-class>
</servlet>

<servlet-mapping>
  <servlet-name>spring-dispatcher</servlet-name>
  <url-pattern>/</url-pattern>
 </servlet-mapping>
    </web-app>

弹簧调度-servlet.xml中

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="
 http://www.springframework.org/schema/beans     
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

  <bean id="HandlerMapping"
 class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>

 <bean name="/welcome.html"
 class="com.controller.HellowController.HelloController"/>

 <bean id="viewResolver"
 class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix" value="/WEB-INF/" />
  <property name="suffix" value=".jsp" />
 </bean>
</beans>

HelloPage.jsp

<html>
 <head>
 <title>Hello Spring MVC</title>
 </head>
 <body>
 <h2>${message}</h2>
 </body>
</html>

HelloController.java

package com.controller.HelloController;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;

  import org.springframework.web.servlet.ModelAndView;
 import org.springframework.web.servlet.mvc.AbstractController;

 public class HelloController extends AbstractController{

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest arg0,   HttpServletResponse arg1) throws Exception {
    ModelAndView modelandview = new ModelAndView("HelloPage");
    modelandview.addObject("message","welcome");
    return modelandview;
    }}

,例外是

  

java.lang.NoSuchMethodError:org.springframework.beans.factory.support.DefaultListableBeanFactory.setSerializationId(Ljava / lang / String;)V           在org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:128)           在org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)           在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)           在org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:427)           在org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:341)           在org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:307)           在org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)           在javax.servlet.GenericServlet.init(GenericServlet.java:158)           在org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1279)           在org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1192)           在org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:864)           在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)           在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)           在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)           在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)           在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)           在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)           在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)           在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)           at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:607)           在org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:313)           at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)           at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)           在java.lang.Thread.run(未知来源)

Mar 28, 2016 2:14:40 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet spring-dispatcher
java.lang.NoSuchMethodError: org.springframework.beans.factory.support.DefaultListableBeanFactory.setSerializationId(Ljava/lang/String;)V
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:128)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:427)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:341)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:307)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1279)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1192)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:864)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

0 个答案:

没有答案