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
share improve this question
 
 
can you post your spring config files and tell us what app-server is it supposed to run on? –   Gergely Szilagyi Jun 27 '12 at 13:33
 
@Gergely Szilagyi, i updated the question. –   MahmoudS  Jun 27 '12 at 13:49
 
deleted my answer, because it wasn't useful. sorry :( –   Gergely Szilagyi  Jun 27 '12 at 14:14
 
Which IDE are you using?? –   iNan  Jun 27 '12 at 14:29
1 
I believe it is not directly a CNF on DispatcherServlet but a dependent class has thrown an error. Check if you see any other nested exception. –   adarshr  Jun 27 '12 at 14:37 

8 Answers

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

  • 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.

That it!! rebuild and deploy again


原文链接:http://stackoverflow.com/questions/11227395/java-lang-classnotfoundexception-org-springframework-web-servlet-dispatcherserv

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值