Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

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

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:

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

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

<?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
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

  • right click on your project and choose properties.
  • click on Deployment Assembly.
  • click add
  • click on "Java Build Path Entries"
  • select Maven Dependencies"
  • click Finish.

Rebuild and deploy again

Note: This is also applicable for non maven project.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...