Java Spring MVC突然类未找到DispatcherServlet

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21705851/
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-08-13 10:10:19  来源:igfitidea点击:

Spring MVC suddenly class Not found DispatcherServlet

javaspringmavenspring-mvcmodel-view-controller

提问by takemylemons

my WebApp was working and everything was fine until i tried to implement some fileupload. But it didnt worked so i just returned everything to the previous state. But since then its not working. My Stacktrace:

我的 WebApp 工作正常,一切正常,直到我尝试实现一些文件上传。但它没有用,所以我只是把所有东西都恢复到以前的状态。但从那时起它就不起作用了。我的堆栈跟踪:

Feb 11, 2014 4:11:35 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\java\jdk1.7.0_25\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\oraclexe\app\oracle\product.2.0\server\bin;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;c:\Program Files\Intel\DMIX;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared.0\DLLShared\;C:\java\SlikSvn\bin;C:\java\apache-maven-3.0.5\bin;C:\java\apache-ant-1.8.4\bin;C:\java\SlikSvn\bin;C:\java\jdk1.7.0_25\bin;C:\oraclexe\app\oracle\product.2.0\server\bin;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;c:\Program Files\Intel\DMIX;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared.0\DLLShared\;C:\java\SlikSvn\bin;C:\Python27\Scripts;C:\Program Files (x86)\Google\google_appengine\;.
Feb 11, 2014 4:11:35 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:springproject' did not find a matching property.
Feb 11, 2014 4:11:36 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Feb 11, 2014 4:11:36 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 521 ms
Feb 11, 2014 4:11:36 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Feb 11, 2014 4:11:36 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.35
Feb 11, 2014 4:11:36 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet ds as unavailable
Feb 11, 2014 4:11:36 PM org.apache.catalina.core.ApplicationContext log
SEVERE: Error loading WebappClassLoader
  context: /springproject
  delegate: false
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@139231a9
 org.springframework.web.servlet.DispatcherServlet
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1128)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

Feb 11, 2014 4:11:36 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /springproject threw load() exception
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1128)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

Feb 11, 2014 4:11:36 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Feb 11, 2014 4:11:36 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Feb 11, 2014 4:11:36 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/13  config=null
Feb 11, 2014 4:11:36 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 672 ms
Feb 11, 2014 4:11:42 PM org.apache.catalina.core.StandardWrapperValve invoke
INFO: Servlet ds is currently unavailable
Feb 11, 2014 4:11:43 PM org.apache.catalina.core.StandardWrapperValve invoke
INFO: Servlet ds is currently unavailable
Feb 11, 2014 4:11:44 PM org.apache.catalina.core.StandardWrapperValve invoke
INFO: Servlet ds is currently unavailable

my Pom.xml

我的 Pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>springproject</groupId>
<artifactId>springproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <warSourceDirectory>WebContent</warSourceDirectory>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
</build>


<dependencies>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.0.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
    </dependency>

    <!-- Spring JDBC -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>
    <!-- H2 Driver -->
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.2.140</version>
    </dependency>

    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20070829</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.Hymanson</groupId>
        <artifactId>Hymanson-core-asl</artifactId>
        <version>1.9.13</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.Hymanson</groupId>
        <artifactId>Hymanson-mapper-asl</artifactId>
        <version>1.9.13</version>
    </dependency>

    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.9</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.1</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>3.2.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>3.2.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>3.2.0.RELEASE</version>
    </dependency>

</dependencies>

my Web.xml:

我的 Web.xml:

<?xml version="1.0" encoding="UTF-8"?>

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://xmlns.jcp.org/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.4">

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/ javaee/web-app_2_5.xsd" version="2.4">

<display-name>springproject</display-name>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/Application-context.xml</param-value>
</context-param>


<!-- Handles all requests into the application -->
<servlet>
    <servlet-name>ds</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring/servlets/servlet-context.xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>ds</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

i tried to clean, republish, update trough maven, delete and restore from backup but it still wont work, please help.

我试图清理,重新发布,更新槽 maven,从备份中删除和恢复,但它仍然无法正常工作,请帮忙。

采纳答案by takemylemons

Ok Guys i could solve this strange bug, the problem was the tomcat Serveri created a new one and then added the Project. and now everything works fine, thank you for your help.

好的,伙计们,我可以解决这个奇怪的错误,问题是我创建了一个新的tomcat 服务器,然后添加了项目。现在一切正常,感谢您的帮助。

回答by bcody

Are you using the Eclipse Web Tools Platform with an Eclipse-managed Tomcat? If so, try cleaning up Tomcat by right-clicking on your server instance's node in the "Servers" view and selecting "Clean..." and "Clean Tomcat Work Directory". If you expand your server's node in that view, you'll see the deployed application. Right click on the application node and select "Clean Module Work Directory..."

您是否将 Eclipse Web 工具平台与 Eclipse 管理的 Tomcat 一起使用?如果是这样,请尝试通过在“服务器”视图中右键单击服务器实例的节点并选择“清理...”和“清理 Tomcat 工作目录”来清理 Tomcat。如果在该视图中展开服务器节点,您将看到已部署的应用程序。右键单击应用程序节点并选择“清理模块工作目录...”

回答by Gabriel Sanmartin

Also, perform a Maven Update (Right click->Maven->Update project...). I have found that sometimes my project loses its dependencies somehow and I get the same exception as you do.

此外,执行 Maven 更新(右键单击->Maven->更新项目...)。我发现有时我的项目会以某种方式失去其依赖项,并且我会遇到与您相同的异常。

回答by Gabriel Sanmartin

If you're using Eclipse, right click on the project, go to Properties, then on the Deployment Assembly click on Add.. -> Java Build Path -> Maven Dependencies. Click Ok, Clean your project and try again. See if that works.

如果您使用 Eclipse,请右键单击项目,转到属性,然后在部署程序集上单击Add.. -> Java Build Path -> Maven Dependencies。单击确定,清理您的项目并重试。看看这是否有效。

回答by mhmpl

Did you checked if the names and paths of your configuration files are correct? Application-context.xmland servlet-context.xml.

您是否检查过配置文件的名称和路径是否正确? Application-context.xmlservlet-context.xml

You said you tried to implement a file upload functionallity. It seems that it broke something. You should try to revert to a version prior to the implementation and check if your webapp works fine then.

您说您尝试实现文件上传功能。似乎打破了什么。您应该尝试恢复到实施之前的版本,然后检查您的 web 应用程序是否正常工作。

回答by Abhishek raut

I any of you face DispatcherServlet.class not found exceptio,follow these steps:

你们中的任何人都遇到 DispatcherServlet.class not found exceptio,请按照以下步骤操作:

  1. You are facing this error because your tomcat version is old (below 6.0) and/or jar files are not placed inside WEB-INF/lib. So build a new (fully blank) dynamic web project. Create the project files (I am talking only the files you create.. i.e. controllers,jsps,htmls,XMLs)
  2. Delete the tomcat server if it is below version 6.0 (Mine was 5.5 and I was facing the same error and then downloaded 6.0) and to delete, go to servers tab which you will find beside 'Console' tab. Delete the server there and then right click on your project, go to configure-> Build Path -> Libraries tab.. 'Remove' the server from there as well..Then build-clean and Refresh the project.
  3. Now go to your browser , download apache tomcat 6.0 version. Paste this downloaded folder in any drive and any folder you want.
  4. Now go back to your IDE, copy the jar files and paste them in WEB-INF/lib folder (DO NOT DO CONFIGURE BUILD-PATH AT ALL because classes like dipatcher servelet will be invoked from WEB-INF/lib folder dynamically by default ..So go to your drive, Copy all jars. and then come back to your IDE..go to your project, paste them inside WEB-INF/lib. Then bulid-clean and Refresh the project. 5.Right click on your project, Run As Run on server. In the popup window, you will see the dropdown for server selection, change to "None" there( This is very important). Click next,then it will ask you to browse to a server folder.SO browse to your downloaded folder, select it press finish. Bingo.Its done.
  1. 您遇到此错误是因为您的 tomcat 版本较旧(低于 6.0)和/或 jar 文件未放置在 WEB-INF/lib 中。因此,构建一个新的(完全空白的)动态 Web 项目。创建项目文件(我只说你创建的文件......即控制器、jsps、htmls、XMLs)
  2. 删除低于 6.0 版本的 tomcat 服务器(我的是 5.5,我遇到了同样的错误,然后下载了 6.0)并删除,转到“控制台”选项卡旁边的服务器选项卡。删除那里的服务器,然后右键单击您的项目,转到配置-> 构建路径-> 库选项卡.. 也从那里“删除”服务器..然后构建清理并刷新项目。
  3. 现在转到您的浏览器,下载 apache tomcat 6.0 版本。将此下载的文件夹粘贴到您想要的任何驱动器和任何文件夹中。
  4. 现在返回到您的 IDE,复制 jar 文件并将它们粘贴到 WEB-INF/lib 文件夹中(完全不要配置 BUILD-PATH,因为默认情况下会从 WEB-INF/lib 文件夹动态调用像 dipatcher servelet 这样的类。 .所以去你的驱动器,复制所有的罐子。然后回到你的IDE..去你的项目,将它们粘贴到WEB-INF/lib中。然后bulid-clean并刷新项目。5.右键单击你的项目, Run As Run on server. 在弹出窗口中,您将看到服务器选择的下拉菜单,在那里更改为“无”(这很重要)。单击下一步,然后它会要求您浏览到服务器文件夹。SO浏览到您下载的文件夹,选择它按完成。宾果游戏。完成。

回答by Deepanshu Ganotra

under servers tab-> click Clean / Clean Tomcat work directory. Also under expand server, right click on deployed application on the server and click "clean module work directory" and restart the server. This resolved my issue of "Dispatcher Servlet class not found". Thank you.

在服务器选项卡下 -> 单击 Clean / Clean Tomcat 工作目录。同样在展开服务器下,右键单击服务器上部署的应用程序,然后单击“清理模块工作目录”并重新启动服务器。这解决了我的“找不到 Dispatcher Servlet 类”的问题。谢谢你。