[英]java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
i am using spring 3.1.0.RELEASE , and my servlet container is tomcat 7 and my IDE is eclipse indigo and the jar spring-webmvc-3.1.0.RELEASE.jar which contains the DispatcherServlet exists in the lib folder, and yet when running the application, i am getting the exception:我正在使用spring 3.1.0.RELEASE ,我的servlet容器是tomcat 7 ,我的IDE是eclipse indigo ,包含DispatcherServlet的jar spring-webmvc-3.1.0.RELEASE.jar存在于lib文件夹中,但是当运行应用程序,我得到了异常:
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:525)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:507)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:126)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1043)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4957)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5284)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5279)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
please advise why i am getting this exception, and how to fix it.请告知我为什么会收到此异常,以及如何解决它。
EDIT: following are my configuration files:编辑:以下是我的配置文件:
1- .springBeans: 1- .springBeans:
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[2.9.0.201203011806-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
<config>src/main/webapp/WEB-INF/checkout-servlet.xml</config>
</configs>
<configSets>
</configSets>
</beansProjectDescription>
2- web.xml: 2- web.xml:
<web-app>
<display-name>Checkout</display-name>
<servlet>
<servlet-name>checkout</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>checkout</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
</web-app>
3- checkout-servlet.xml: 3-结帐-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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan base-package="com.myapp"/>
<bean id="myService" class="com.myapp.MyService"/>
</beans>
also when trying to access any page in the application, i get the exception:同样在尝试访问应用程序中的任何页面时,我得到了异常:
HTTP Status 404 - Servlet checkout is not available
type Status report
message Servlet checkout is not available
description The requested resource (Servlet checkout is not available) is not available.
Apache Tomcat/7.0.22
You need to add the "Maven Dependency" in the Deployment Assembly您需要在部署程序集中添加“Maven 依赖项”
Rebuild and deploy again重新构建和部署
Note: This is also applicable for non maven project.注意:这也适用于非 Maven项目。
Two possible answers:两个可能的答案:
1- You did not include spring-beans and spring-context jars in your lib. 1-您的库中没有包含 spring-beans 和 spring-context jar。 If you are using maven (which will help a lot) those two lines will be enough
如果您使用的是 maven(这将有很大帮助),那么这两行就足够了
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
2- The necessary jars are in your classpath but are not deployed on tomcat. 2- 必要的 jar 在您的类路径中,但未部署在 tomcat 上。
I had the same problem with Idea Intellij and Spring 4. I fixed the problem and I wanted to share the answer with you.我在使用 Idea Intellij 和 Spring 4 时遇到了同样的问题。我解决了这个问题,我想与你分享答案。
I use tomcat 7 / idea intellij 13 / spring 4.我使用 tomcat 7/idea intellij 13/spring 4。
pom.xml dependencies: pom.xml 依赖项:
<properties>
<spring.version>4.0.5.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
enter code here
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
In idea Intellij, you need to go to File -> Project Settings -> Artifacts.在idea Intellij 中,您需要转到文件-> 项目设置-> 工件。
Then然后
clean -> rebuild the project -> build the artifact, and everything will be ok.清理 -> 重建项目 -> 构建工件,一切都会好的。
This solves the problem for me.这为我解决了这个问题。 It's easy and pretty simply explained.
这很容易而且很简单地解释了。
Step 1步骤1
Step 2第2步
Step 3第 3 步
Step 4第4步
Step 5第 5 步
i found that in the deployment assembly , there was the entry:我发现在部署程序集中,有以下条目:
[persisted container] org.maven.ide.eclipse.maven2_classpath_container
i removed it, and added the maven dependencies
entry, and it works fine now.我删除了它,并添加了
maven dependencies
项,现在它工作正常。
If all of these advice doesn't work, you should re-create your Server (Tomcat or like that).如果所有这些建议都不起作用,您应该重新创建服务器(Tomcat 或类似的)。 That solved my problem.
这解决了我的问题。
Include below dependency in your pom.xml在您的 pom.xml 中包含以下依赖项
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>{spring-version}</version>
</dependency>
I was facing the same Issue.我面临着同样的问题。 When I saw into maven repository .m2 folder(....m2\repository\org\springframework\spring-webmvc) in my local I found two 3.2.0.RELEASE folders.
当我在本地查看 maven 存储库 .m2 文件夹(....m2\repository\org\springframework\spring-webmvc)时,我发现了两个 3.2.0.RELEASE 文件夹。 SO I removed one.
所以我删除了一个。 Then I went to project, right click->properties->deployment essembly-> add maven dependencies.
然后我去project,右键->properties->deployment essembly->add maven dependencies。 clean build and then restart the server.
清理构建,然后重新启动服务器。 Then the DispatcherServlet got loaded.
然后 DispatcherServlet 被加载。
In my case I get this trouble after using the maven's update project utility.在我的情况下,我在使用 maven 的更新项目实用程序后遇到了这个问题。 I tried all the workarounds you suggested but nothing seemed to work.
我尝试了您建议的所有解决方法,但似乎没有任何效果。 At the end the solution was simply to remove the project from the server to ensure that it was clean, and add it again.
最后,解决方案只是从服务器中删除项目以确保它是干净的,然后再次添加它。 Then it works, I hope this solution could help any of you.
然后它起作用了,我希望这个解决方案可以帮助你们中的任何人。
You can use GlassFish server and the error will be resolved.您可以使用 GlassFish 服务器,错误将得到解决。 I tried with tomcat7 and tomcat8 but this error was coming continuously but resolved with GlassFish.
我尝试使用 tomcat7 和 tomcat8,但此错误不断出现,但使用 GlassFish 解决了。 I think it's a problem with server.
我觉得是服务器的问题。
right click on your project and choose properties.右键单击您的项目并选择属性。 click on Deployement Assembly.
单击部署程序集。 click add click on "Java Build Path Entries" select Maven Dependencies" click Finish.
单击添加单击“Java 构建路径条目”选择 Maven 依赖项“单击完成。
It may be useful for someone, so I'll post it here.它可能对某人有用,所以我会在这里发布。 I was missing this dependency on my
pom.xml
我错过了对我的
pom.xml
的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
I solved by following these steps:我通过以下步骤解决了:
This fixes the "Deployment Assembly" settings of the project.这修复了项目的“部署程序集”设置。
将 jar 文件从类路径移动到web-inf/lib ,然后运行一个新的 tomcat 服务器。
我找到了一个简单的解决方案,只需将您的 jars 添加到 WEB-INF-->lib 文件夹中..
I had this same issue in WebSphere, but couldn't find a solution even though I verified the Spring dependencies were there and it ran in tomcat just fine.我在 WebSphere 中遇到了同样的问题,但即使我验证了 Spring 依赖项在那里并且它在 tomcat 中运行得很好,也找不到解决方案。 I ended up uninstalling the application and was still getting the error so I think WebSphere was hanging onto some corrupt instance.
我最终卸载了应用程序,但仍然收到错误,所以我认为 WebSphere 挂在了一些损坏的实例上。
To fix the issue I had to reinstall the application, stop it, uninstall it and then reinstall it.为了解决这个问题,我必须重新安装应用程序,停止它,卸载它,然后重新安装它。
For me it was a mistake in the pom.xml
- I'd set <scope>provided<scope>
on my dependencies, and this was making them not get copied during the mvn package
stage.对我来说,这是
pom.xml
中的一个错误——我在我的依赖项上设置<scope>provided<scope>
,这使得它们在mvn package
阶段不会被复制。
My symptoms were the error message the OP posted, and that the jars were not included in the WEB-INF/lib path inside the .war after package was run.我的症状是 OP 发布的错误消息,并且运行包后 .war 内的 WEB-INF/lib 路径中未包含 jar 包。 When I removed the scope, the jars appeared in the output, and all loads up fine now.
当我删除范围时,罐子出现在输出中,现在一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.