eclipse spring mvc项目中servlet不可用错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5033384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
servlet not available error in eclipse spring mvc projects
提问by
i am running the project using eclipse. in one project i get the following error
我正在使用 eclipse 运行该项目。在一个项目中,我收到以下错误
18/02/2011 12:23:41 AM org.apache.catalina.core.AprLifecycleListener init INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\java\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\java\bin;C:\Program Files (x86)\MySQL\MySQL Server 5.1\bin;C:\Program Files (x86)\IDM Computer Solutions\UltraEdit\;C:\java\bin 18/02/2011 12:23:42 AM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:test' did not find a matching property. 18/02/2011 12:23:42 AM org.apache.coyote.AbstractProtocolHandler init INFO: Initializing ProtocolHandler ["http-bio-8085"] 18/02/2011 12:23:42 AM org.apache.coyote.AbstractProtocolHandler init INFO: Initializing ProtocolHandler ["ajp-bio-8009"] 18/02/2011 12:23:42 AM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 511 ms 18/02/2011 12:23:42 AM org.apache.catalina.core.StandardService startInternal INFO: Starting service Catalina 18/02/2011 12:23:42 AM org.apache.catalina.core.StandardEngine startInternal INFO: Starting Servlet Engine: Apache Tomcat/7.0.8 18/02/2011 12:23:42 AM org.apache.catalina.core.ApplicationContext log INFO: Marking servlet ds as unavailable 18/02/2011 12:23:42 AM org.apache.catalina.core.StandardContext loadOnStartup SEVERE: Servlet /test threw load() exception java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1048) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:996) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4834) at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5155) at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5150) 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) 18/02/2011 12:23:42 AM org.apache.coyote.AbstractProtocolHandler start INFO: Starting ProtocolHandler ["http-bio-8085"] 18/02/2011 12:23:42 AM org.apache.coyote.AbstractProtocolHandler start INFO: Starting ProtocolHandler ["ajp-bio-8009"] 18/02/2011 12:23:42 AM org.apache.catalina.startup.Catalina start INFO: Server startup in 332 ms 18/02/2011 12:23:52 AM org.apache.catalina.core.StandardWrapperValve invoke INFO: Servlet ds is currently unavailable
18/02/2011 12:23:41 AM org.apache.catalina.core.AprLifecycleListener init INFO:在 java.library.path 中找不到基于 APR 的 Apache Tomcat Native 库,该库可在生产环境中实现最佳性能:C: \java\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\java\bin;C:\Program Files (x86)\MySQL\MySQL Server 5.1\bin;C:\Program Files (x86)\IDM Computer Solutions\UltraEdit\;C:\java\bin 18/02/2011 12:23:42 AM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING : [SetPropertiesRule]{Server/Service/Engine/Host/Context} 将属性 'source' 设置为 'org.eclipse.jst.jee.server:test' 没有找到匹配的属性。18/02/2011 12:23:42 AM org.apache.coyote.AbstractProtocolHandler init INFO:初始化 ProtocolHandler [“http-bio-8085”
my ds.servlet is
我的 ds.servlet 是
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.orf/schema/beans/spring-beans-2.0.xsd">
<!-- Configuring DataSource -->
<bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/springdb</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
<!-- Configuring jdbcTemplate -->
<bean id="jdbctemp" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg>
<ref local="datasource" />
</constructor-arg>
</bean>
<bean id="loginModel" class="com.santosh.spring.LoginModel">
<constructor-arg>
<ref local="jdbctemp" />
</constructor-arg>
</bean>
<bean id="logincnt" class="com.santosh.spring.LoginController">
<property name="loginModel" >
<ref local="loginModel"/>
</property>
<!-- Configure Command ClassName -->
<property name="commandClass" >
<value type="java.lang.Class"> com.santosh.spring.UserDetails </value>
</property>
<!-- Configure the command name , the name to use when binding the instantiated command class to the request -->
<property name="commandName">
<value> UserDetails </value>
</property>
</bean>
<!-- Configure URL Mapping -->
<bean id="myurlmapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
<property name="mappings">
<props>
<prop key="/login.spring">logincnt</prop>
</props>
</property>
<property name="urlMap">
<map>
<entry key="/hello.springs">
<ref bean="helloController"/>
</entry>
</map>
</property>
</bean>
<bean id="helloController" class="net.roseindia.web.HelloWorldController"> </bean>
</beans>
采纳答案by rahulmohan
Dave is right. However, Tomcat has some hot-deployment issues because of which it sometimes fails to load the class which is actually present in the classpath. So, if you find that you actually have the jar at the right place, then simply clean the tomcat (right click the server and select clean) and then start again.
戴夫是对的。但是,Tomcat 存在一些热部署问题,因此有时无法加载类路径中实际存在的类。所以,如果你发现你确实在正确的地方有 jar,那么只需清理 tomcat(右键单击服务器并选择清理)然后重新开始。
回答by Upgradingdave
The stack trace is complaining that it can't find "org.springframework.web.servlet.DispatcherServlet". DispatcherServlet class can be found inside spring-webmvc.jar (jarfinder.comis a good tool for figuring out which jars contain which classes), so double check that you have all the appropriate spring jars, like spring-core-x.jar, spring-webmvc-x.jar, etc on your class path in Eclipse (or perhaps under WEB-INF/lib, depending on how you're trying to run the webapp). Maven repositoryis a good place to find the spring jars if you need them.
堆栈跟踪抱怨它找不到“org.springframework.web.servlet.DispatcherServlet”。DispatcherServlet 类可以在 spring-webmvc.jar 中找到(jarfinder.com是确定哪些 jar 包含哪些类的好工具),因此请仔细检查您是否拥有所有合适的 spring jar,例如 spring-core-x.jar, spring-webmvc-x.jar 等位于 Eclipse 中的类路径上(或者可能在 WEB-INF/lib 下,具体取决于您尝试运行 web 应用程序的方式)。如果需要,Maven 存储库是查找 spring jar 的好地方。