Tomcat没有加载Dispatcher Servlet(ClassNotFoundException)

时间:2013-07-02 10:45:24

标签: spring tomcat spring-mvc

我已尝试根据上述问题的答案进行搜索和更改,但无法正常工作。我没有使用任何构建工具。

所有jar文件jstl1.2,常用loggings 1.1.3和Spring 3.2.3 jar都在WebContent / WEB-INF / lib中

index.jsp是欢迎文件在Eclipse浏览器中正确显示,但是当我单击控制器的超链接时,请提供404请求的资源不可用。从日志看来tomcat没有加载调度程序servlet

我尝试重启/清理并发布tomcat,

使用tomcat 7,jre7,eclipse kepller 4.0,使用java ee 2.0

感谢您的帮助

Tomcat日志:

   ul 02, 2013 1:16:52 PM org.apache.catalina.core.ApplicationContext log
    I**NFO: No Spring WebApplicationInitializer types detected on classpath
    Jul 02, 2013 1:16:52 PM org.apache.catalina.core.ApplicationContext log
    INFO: Marking servlet spring as unavailable
    Jul 02, 2013 1:16:52 PM org.apache.catalina.core.StandardContext loadOnStartup
    SEVERE: Servlet /SpringMVC threw load() exception
    java.lang.ClassNotFoundException:             org.springframework.web.servlet.DispatcherServlet**
            
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5123)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5407)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Jul 02, 2013 1:16:53 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jul 02, 2013 1:16:53 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jul 02, 2013 1:16:53 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 11462 ms

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>SpringMVC</display-name>

     <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
 
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
</web-app>

弹簧servlet.xml中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"

    xsi:schemaLocation="http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                        http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan
        base-package="com.maverick.springmvc.controller" />

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

</beans>

HelloWorldController.java

package com.maverick.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class HelloWorldController {


    @RequestMapping("/hello")
    public ModelAndView helloWorld() {

        System.out.println("test");
        String message = "Hello World, Spring 3.0!";
        return new ModelAndView("hello", "message", message);
    }
}

2 个答案:

答案 0 :(得分:2)

基于堆栈跟踪,您缺少包含DispatcherServlet类的spring-webmvc.jar。再次检查你的类路径(WEB-INF / lib)以确保jar在那里。通常在Spring MVC应用程序中,您需要这些jar:

enter image description here

我还建议你使用依赖管理工具(例如:Maven / ivy),否则你自己管理罐子太难了

答案 1 :(得分:0)

只需将所有需要的jar文件添加到WEB-INF / lib文件夹,然后它就适合我。 在这种情况下,只发现DispatcherServlet类