Spring Java Config: Tomcat deploy without web.xml
Asked Answered
M

2

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.

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 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
Mukund answered 3/2, 2014 at 14:13 Comment(7)
What are your startup logs showing?Woody
Just "INFO: Deploying web application archive [appname].war" in catalina.outMukund
Change Spring logging to a DEBUG and check.Woody
Please check update: But I still do not get more information.Mukund
How does the server used in Eclipse differ from the test server? Is it the same tomcat version?Annexation
No the test server uses tomcat6. As soon as I am using following goal to run my application locally, I am facing the same problem like on the server. (org.apache.tomcat.maven:tomcat6-maven-plugin:2.1:run). So it seems that the problem is the tomcat version. (Must be tomcat7) I will check this and post my solution.Mukund
Tomcat6 doesn't support Java config. You need a recent version of Tomcat 7 to support that. Early versios of Tomcat 7 had problems with Java config.Annexation
C
1

If this still isn't solved, it is possibly due to the Servlet version. The Servlet 3.x API is required to have the possibility to configure a java web application by writing a java class instead of having a web.xml file inside the WEB-INF folder.

see here for a complete example.

Commodore answered 7/3, 2014 at 13:21 Comment(0)
A
1

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

Mapping to '/' under Tomcat

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.

Abib answered 11/8, 2014 at 15:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.