Spring Java Config:不使用web.xml的Tomcat部署 [英] Spring Java Config: Tomcat deploy without web.xml
问题描述
我构建了一个没有任何XML的Java配置的Spring MVC应用程序.我可以在笔记本电脑上部署并启动该应用程序,而不会出现任何问题.但是,一旦我尝试在我的测试服务器(tomcat 7)上部署应用程序,就会收到以下消息:
I built a java configured Spring MVC application without any XML. I can deploy and start the application on my laptop without any problems. But as soon as I try to deploy my application on my testserver (tomcat 7), I receive following message:
HTTP Status 404 - The requested resource (/[application context]/) is not available.
我使用Eclipse Maven插件构建应用程序.是否可以在没有web.xml的情况下部署应用程序,如果没有,这是我真正需要的基本web.xml?
I build my applications using the Eclipse Maven plugin. Is it possible to deploy the application without the web.xml and if not, which is the basic web.xml I really need?
Maven WAR插件:
Maven WAR Plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven.war.plugin.version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
WebAppInitializer:
WebAppInitializer:
@Order(value = 1)
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
}
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { HibernateConfig.class, SecurityConfig.class, HibernateDaoConfig.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[] { WebAppConfig.class };
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
@Override
protected Filter[] getServletFilters() {
return new Filter[]{};
}
}
更新:catalina.out
Update: catalina.out
Feb 3, 2014 4:18:32 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/[appname]] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.
Feb 3, 2014 4:18:33 PM org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context [/[appname]]
Feb 3, 2014 4:18:45 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive [appname].war
推荐答案
我将升级到最新的Tomcat版本,然后查看它是否有效(以隔离您的问题).在较旧的Tocmat服务器上使用新的spring功能(例如:java config等)有很多问题.例如,请参见:
I'd upgrade to the latest Tomcat version and see if that works (to isolate your issue). There are many issues with using the new spring features (ex: java config, etc.) with older Tocmat servers. For example, see: http://docs.spring.io/autorepo/docs/spring-framework/3.1.x/javadoc-api/org/springframework/web/WebApplicationInitializer.html
在Tomcat下映射到'/'
Mapping to '/' under Tomcat
Apache Tomcat将其内部DefaultServlet映射为"/",并且在Tomcat版本< = 7.0.14上,不能以编程方式覆盖此>> servlet映射. 7.0.15解决了此问题.覆盖"/" >> servlet映射也已在GlassFish 3.1下成功测试.
Apache Tomcat maps its internal DefaultServlet to "/", and on Tomcat versions <= 7.0.14, this >>servlet mapping cannot be overridden programmatically. 7.0.15 fixes this issue. Overriding the "/" >>servlet mapping has also been tested successfully under GlassFish 3.1.
这篇关于Spring Java Config:不使用web.xml的Tomcat部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!