我在Eclipse Indigo中使用Spring MVC 3.2.0,Tomcat 7.0.27启动我的Webapp时遇到了问题。从昨天开始,一切都很好。但现在看来我的Webapp将无法正确部署。
...
Jan 06, 2013 12:04:49 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 477 ms
Jan 06, 2013 12:04:49 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jan 06, 2013 12:04:49 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.27
Jan 06, 2013 12:04:50 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Jan 06, 2013 12:04:51 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Jan 06, 2013 12:04:51 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory <...>.metadata\.plugins\org.eclipse.wst.server.core\tmp0\webapps\...
Jan 06, 2013 12:04:52 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Jan 06, 2013 12:04:52 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-80"]
Jan 06, 2013 12:04:52 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jan 06, 2013 12:04:52 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jan 06, 2013 12:04:52 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2800 ms
只有消息
信息:没有在类路径上检测到Spring WebApplicationInitializer类型
我觉得部署webapp存在问题
当我调用URL时
本地主机:8080 / myWebApp
我只看到目录列表
我做了什么:我从source
删除了我的webApp的server.xml
属性,我的/WEB-INF/web.xml
看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
我将servlet定义放入/WEB-INF
,看起来像这样:
<?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:p="http://www.springframework.org/schema/p"
xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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.0.xsd
http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd">
<context:component-scan base-package="net.tud.vorlesung" />
<mvc:annotation-driven />
</beans>
当我从一个升级的IDE打开一个旧的项目时,我发生了这种情况,所以这有助于我解决问题Right Click on my project -> Maven -> Update Project...
为了解决这个问题,我将描述如何修复自己的问题。
至少问题是我的项目发布到我的本地服务器,我想不是所有已构建的类都已部署。
使用Maven时,似乎有必要将maven-lib包添加到项目部署程序集(项目>右键单击>属性>部署程序集)。
此外,如果您的控制台显示NoClassDef-Exception,您应该“清理”您的ServerDeployment。这可以用Eclipse完成(我使用Juno)。只需右键单击您的服务器,然后单击“清除...”。
重新部署需要多长时间取决于您的项目。在我的项目中,它需要> 5分钟。
如果这不起作用,请首先尝试使用“真正的”JAR而不是Maven。其实我和耶拿有问题(见Sparql Select Query works on Sesame-Workbench but not on Java)
希望这会对很多人有所帮助。