. lang。ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet

时间:2021-11-04 00:09:33

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。我的servlet容器是tomcat 7,我的IDE是eclipse indigo和jar spring-webmvc-3.1.0.RELEASE。包含DispatcherServlet的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 - checkout-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

14 个解决方案

#1


205  

You need to add the "Maven Dependency" in the Deployment Assembly

您需要在部署程序集中添加“Maven依赖项”

  • right click on your project and choose properties.
  • 右键单击项目并选择properties。
  • click on Deployment Assembly.
  • 点击部署大会。
  • click add
  • 单击add
  • click on "Java Build Path Entries"
  • 点击“Java构建路径条目”
  • select Maven Dependencies"
  • 选择Maven依赖”
  • click Finish.
  • 单击Finish。

Rebuild and deploy again

重建和重新部署

Note: This is also applicable for non maven project.

注意:这也适用于非maven项目。

#2


26  

Two possible answers:

两个可能的答案:

1- You did not include spring-beans and spring-context jars in your lib. If you are using maven (which will help a lot) those two lines will be enough

1-你的库中没有包含spring-beans和spring-context jar

<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上部署。

#3


16  

Hi guys 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

砰的一声。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. Then . lang。ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet

在idea Intellij中,你需要去文件>项目设置>工件。然后

clean -> rebuild the project -> build the artifact and everything will be ok ...

clean ->重新构建项目——>构建工件,一切都会好起来……

#4


8  

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依赖项条目,现在它运行良好。

#5


4  

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. SO I removed one. Then I went to project, right click->properties->deployment essembly-> add maven dependencies. clean build and then restart the server. Then the DispatcherServlet got loaded.

我也面临着同样的问题。当我看到到maven库.m2文件夹(.... m2 \ repository \ org \ springframework \ spring-webmvc)在我的地方我发现两个3.2.0。发布文件夹。所以我删除了。然后我去了项目,右击->属性->部署简单->添加maven依赖项。清理构建,然后重新启动服务器。然后DispatcherServlet被加载。

#6


4  

If all of these advice doesn't work, you should re-create your Server (Tomcat or like that). That solved my problem.

如果所有这些建议都不起作用,您应该重新创建您的服务器(Tomcat或类似的)。这解决了我的问题。

#7


2  

In my case I get this trouble after using the maven's update project utility. 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.

在我的例子中,我在使用maven的更新项目实用程序后遇到了麻烦。我试了你建议的所有变通办法,但似乎什么都不管用。最后,解决方案只是将项目从服务器中删除,以确保项目是干净的,并再次添加它。我希望这个解决方案能对你们中的任何一个人有所帮助。

#8


2  

You can use GlassFish server and the error will be resolved. I tried with tomcat7 and tomcat8 but this error was coming continuously but resolved with GlassFish. I think it's a problem with server.

您可以使用GlassFish服务器,错误将被解决。我试过用tomcat7和tomcat8,但是这个错误一直在发生,但是用GlassFish解决了。我认为这是服务器的问题。

These are the results with tomcat7: . lang。ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet

这是tomcat7的研究结果:

Here are the results with GlassFish: . lang。ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet

下面是玻璃鱼的结果:

#9


2  

Include below dependency in your pom.xml

在您的blog .xml中包含以下依赖项

<dependency>
 <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
   <version>{spring-version}</version>
</dependency>

#10


1  

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.

右键单击项目并选择properties。点击Deployement组装。单击“Java构建路径条目”“选择Maven依赖项”单击“完成”。

#11


0  

I solved by following these steps:

我通过以下步骤来解决:

  • Right click in the project > Configure > Convert to Maven project
  • 在项目>中右键单击配置>转换为Maven项目。
  • After the conversion, right click in the project > Maven > Update project
  • 转换后,右键单击项目> Maven >更新项目

This fixes the "Deployment Assembly" settings of the project.

这将修复项目的“部署程序集”设置。

#12


0  

Move the jar files from your classpath to web-inf/lib, and run a new tomcat server.

将jar文件从类路径移动到web-inf/lib,并运行一个新的tomcat服务器。

#13


0  

I found a simple solution, Simply add your jars inside WEB-INF-->lib folder..

我找到了一个简单的解决方案,就是在WEB-INF- >lib文件夹中添加jar。

#14


-1  

This solves the problem for me. It's easy and pretty simply explained.

这解决了我的问题。解释起来很简单。

Step 1

步骤1

  • Right click on project
  • 右键单击项目
  • Click on Properties
  • 点击属性

Step 2

步骤2

  • Click on Deployment Assembly Tab in the
  • 单击部署程序集选项卡
  • Click Add...
  • 单击Add……

Step 3

步骤3

  • Click on Java Build Path Entries
  • 单击Java构建路径条目

Step 4

步骤4

  • Click on Maven Dependencies
  • 点击Maven的依赖关系
  • Click Finish button
  • 单击Finish按钮

Step 5

步骤5

  • Redeploy Spring MVC application to Tomcat again
  • 重新部署Spring MVC应用程序到Tomcat
  • Restart Tomcat
  • 重启Tomcat
  • List item
  • 列表项

classnotfoundexception

classnotfoundexception

#1


205  

You need to add the "Maven Dependency" in the Deployment Assembly

您需要在部署程序集中添加“Maven依赖项”

  • right click on your project and choose properties.
  • 右键单击项目并选择properties。
  • click on Deployment Assembly.
  • 点击部署大会。
  • click add
  • 单击add
  • click on "Java Build Path Entries"
  • 点击“Java构建路径条目”
  • select Maven Dependencies"
  • 选择Maven依赖”
  • click Finish.
  • 单击Finish。

Rebuild and deploy again

重建和重新部署

Note: This is also applicable for non maven project.

注意:这也适用于非maven项目。

#2


26  

Two possible answers:

两个可能的答案:

1- You did not include spring-beans and spring-context jars in your lib. If you are using maven (which will help a lot) those two lines will be enough

1-你的库中没有包含spring-beans和spring-context jar

<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上部署。

#3


16  

Hi guys 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

砰的一声。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. Then . lang。ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet

在idea Intellij中,你需要去文件>项目设置>工件。然后

clean -> rebuild the project -> build the artifact and everything will be ok ...

clean ->重新构建项目——>构建工件,一切都会好起来……

#4


8  

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依赖项条目,现在它运行良好。

#5


4  

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. SO I removed one. Then I went to project, right click->properties->deployment essembly-> add maven dependencies. clean build and then restart the server. Then the DispatcherServlet got loaded.

我也面临着同样的问题。当我看到到maven库.m2文件夹(.... m2 \ repository \ org \ springframework \ spring-webmvc)在我的地方我发现两个3.2.0。发布文件夹。所以我删除了。然后我去了项目,右击->属性->部署简单->添加maven依赖项。清理构建,然后重新启动服务器。然后DispatcherServlet被加载。

#6


4  

If all of these advice doesn't work, you should re-create your Server (Tomcat or like that). That solved my problem.

如果所有这些建议都不起作用,您应该重新创建您的服务器(Tomcat或类似的)。这解决了我的问题。

#7


2  

In my case I get this trouble after using the maven's update project utility. 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.

在我的例子中,我在使用maven的更新项目实用程序后遇到了麻烦。我试了你建议的所有变通办法,但似乎什么都不管用。最后,解决方案只是将项目从服务器中删除,以确保项目是干净的,并再次添加它。我希望这个解决方案能对你们中的任何一个人有所帮助。

#8


2  

You can use GlassFish server and the error will be resolved. I tried with tomcat7 and tomcat8 but this error was coming continuously but resolved with GlassFish. I think it's a problem with server.

您可以使用GlassFish服务器,错误将被解决。我试过用tomcat7和tomcat8,但是这个错误一直在发生,但是用GlassFish解决了。我认为这是服务器的问题。

These are the results with tomcat7: . lang。ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet

这是tomcat7的研究结果:

Here are the results with GlassFish: . lang。ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet

下面是玻璃鱼的结果:

#9


2  

Include below dependency in your pom.xml

在您的blog .xml中包含以下依赖项

<dependency>
 <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
   <version>{spring-version}</version>
</dependency>

#10


1  

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.

右键单击项目并选择properties。点击Deployement组装。单击“Java构建路径条目”“选择Maven依赖项”单击“完成”。

#11


0  

I solved by following these steps:

我通过以下步骤来解决:

  • Right click in the project > Configure > Convert to Maven project
  • 在项目>中右键单击配置>转换为Maven项目。
  • After the conversion, right click in the project > Maven > Update project
  • 转换后,右键单击项目> Maven >更新项目

This fixes the "Deployment Assembly" settings of the project.

这将修复项目的“部署程序集”设置。

#12


0  

Move the jar files from your classpath to web-inf/lib, and run a new tomcat server.

将jar文件从类路径移动到web-inf/lib,并运行一个新的tomcat服务器。

#13


0  

I found a simple solution, Simply add your jars inside WEB-INF-->lib folder..

我找到了一个简单的解决方案,就是在WEB-INF- >lib文件夹中添加jar。

#14


-1  

This solves the problem for me. It's easy and pretty simply explained.

这解决了我的问题。解释起来很简单。

Step 1

步骤1

  • Right click on project
  • 右键单击项目
  • Click on Properties
  • 点击属性

Step 2

步骤2

  • Click on Deployment Assembly Tab in the
  • 单击部署程序集选项卡
  • Click Add...
  • 单击Add……

Step 3

步骤3

  • Click on Java Build Path Entries
  • 单击Java构建路径条目

Step 4

步骤4

  • Click on Maven Dependencies
  • 点击Maven的依赖关系
  • Click Finish button
  • 单击Finish按钮

Step 5

步骤5

  • Redeploy Spring MVC application to Tomcat again
  • 重新部署Spring MVC应用程序到Tomcat
  • Restart Tomcat
  • 重启Tomcat
  • List item
  • 列表项

classnotfoundexception

classnotfoundexception