我正在使用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)
请告知为什么我遇到此异常,以及如何解决它。
编辑:以下是我的配置文件:
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>
当尝试访问应用程序中的任何页面时,也会出现异常:
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
你需要在部署程序集中添加“ Maven依赖项”
再次重建并部署
注意:这也适用于非Maven项目。