spring Tomcat 未加载 Dispatcher Servlet (ClassNotFoundException)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17423551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 06:02:56  来源:igfitidea点击:

Tomcat not loading Dispatcher Servlet (ClassNotFoundException)

springtomcatspring-mvc

提问by user2477933

I have tried to search and make changes as per answers for above question, but not working. I am not using any build tool.

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

All the jar files jstl1.2, common loggings 1.1.3 , and Spring 3.2.3 jars are in WebContent/WEB-INF/lib

所有 jar 文件 jstl1.2、common logging 1.1.3 和 Spring 3.2.3 jar 都在 WebContent/WEB-INF/lib 中

index.jsp is welcome file is shown properly in Eclipse browser, but when I click on hyperlink for controller, give 404 Requested resource not available. From the log seems tomcat is not loading dispatcher servlet

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

I tried restarting/clean and publish tomcat,

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

using tomcat 7, jre7, eclipse kepller 4.0, with java ee 2.0

使用 tomcat 7、jre7、eclipse keppler 4.0、java ee 2.0

Appreciate your help

感谢你的帮助

Tomcat logs:

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

<?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>

spring-servlet.xml

spring-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

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);
    }
}

回答by gerrytan

Based on the stack trace you are missing spring-webmvc.jar which contains DispatcherServlet class. Try check your classpath again (WEB-INF/lib) to make sure that jar is there. Typically on a Spring MVC application you'll need these jars:

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

enter image description here

在此处输入图片说明

I also recommend you use dependency management tool (eg: Maven / ivy) otherwise it's too hard to manage the jars yourselves

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

回答by Chandrasekhar Allu

Just add all needed jar files to WEB-INF/lib folder, then it works for me. in this case only that DispatcherServlet class found

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