Spring Java configuration: deploying Tomcat without web.xml

I built a Spring MVC Java application without XML. I can deploy and run the application on my laptop without any problems. But as soon as I try to deploy my application on my testerver server (tomcat 7), I get the following message:

HTTP Status 404 - The requested resource (/[application context]/) is not available. 

I create my applications using the Eclipse Maven plugin. Is it possible to deploy the application without web.xml, and if not, is this the basic web.xml I really need?

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:

 @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[]{}; } } 

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 
+6
spring spring-java-config maven tomcat maven-tomcat-plugin
source share
2 answers

If this has not been decided yet, it may be due to the version of Servlet. The Servlet 3.x API should be able to customize the java web application by writing a Java class instead of having the web.xml file inside the WEB-INF folder.

see here for a complete example.

+1
source share

I would upgrade to the latest version of Tomcat and see if this works (to isolate your problem). There are many problems using the new spring features (for example: java config, etc.) with old Tocmat servers. For example, see http://docs.spring.io/autorepo/docs/spring-framework/3.1.x/javadoc-api/org/springframework/web/WebApplicationInitializer.html

Display in '/' under Tomcat

Apache Tomcat maps its internal DefaultServlet to the name "/", and in versions of Tomcat <= 7.0.14 this → servlet mapping cannot be overridden programmatically. 7.0.15 fixes this problem. Overriding the "/" → servlet display has also been successfully tested in GlassFish 3.1.

+1
source share

All Articles