Tomcat 7 hangs on Initializing Spring root WebApplicationContext
Asked Answered
C

4

20

I am trying to deploy a Spring web application to Tomcat 7.0.24 but it hangs upon startup with the last lines showing as

INFO: Deploying web application archive /usr/local/apps/tomcat-7.0.42/webapps/server-webapp.war
Apr 4, 2014 1:38:28 PM org.apache.catalina.core.ApplicationContext log
INFO: Spring WebApplicationInitializers detected on classpath: [com.verical.marketplace.init.MarketplaceWebAppInitializer@6a05fdf]
Apr 4, 2014 1:38:30 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext

I recently upgraded to Spring 4.0.2 and am using a customer WebApplicationInitializer via annotations. Before the upgrade I was using Spring 3 with pure XML config and it worked just fine. My web.xml file looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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_3_0.xsd
     http://java.sun.com/xml/ns/javaee/web-common_3_0.xsd"
     version="3.0">

<!-- Define the mime mappings -->
<mime-mapping>
    <extension>xsd</extension>
    <mime-type>text/xml</mime-type>
</mime-mapping>

<!-- Define the welcome file list -->
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<!-- Define the default session timeout value -->
<session-config>
    <session-timeout>240</session-timeout>
    <cookie-config>
        <http-only>true</http-only>
        <secure>true</secure>
    </cookie-config>
</session-config>

Here is my web application initializer:

public class MarketplaceWebAppInitializer implements WebApplicationInitializer
{
  @Override
  public void onStartup(ServletContext container)
  {
    // Instantiate a new web application context
    XmlWebApplicationContext rootContext = new MarketplaceXmlWebApplicationContext(container);

    // Add the various listeners
    container.addListener(new ContextLoaderListener(rootContext));
    container.addListener(new RequestContextListener());

    // Set the locations of the configuration files
    rootContext.setConfigLocations(
            new String[]
                    {
                            "applicationContext.xml",
                            "config/api-beans.xml",
                            "config/hibernate-beans.xml",
                            "config/security-beans.xml",
                            "config/service-beans.xml",
                            "config/settings-beans.xml",
                            "config/utility-beans.xml",
                            "config/mvc/web-beans.xml",
                            "config/jmx-beans.xml",
                            "config/ws/ws-beans.xml"
                    }
    );

    // Add the dispatcher servlet
    ServletRegistration.Dynamic mvc =
            container.addServlet("mvc", new DispatcherServlet(rootContext));
    mvc.setLoadOnStartup(1);
    mvc.setInitParameter("dispatchOptionsRequest", "true");
    mvc.addMapping("/api/*");
    mvc.addMapping("/html/*");

    // Add the web services servlet
    ServletRegistration.Dynamic ws =
            container.addServlet("ws", new MessageDispatcherServlet(rootContext));
    ws.setLoadOnStartup(2);
    ws.setInitParameter("transformWsdlLocations", "true");
    ws.addMapping("/service/*");

    // Add the spring security filter
    FilterRegistration.Dynamic springSecurityFilter =
            container.addFilter("springSecurityFilterChain",
                    new DelegatingFilterProxy("springSecurityFilterChain"));
    springSecurityFilter.addMappingForUrlPatterns(null, true, "/j_spring_security_check");
    springSecurityFilter.addMappingForUrlPatterns(null, true, "/j_spring_security_logout");
    springSecurityFilter.addMappingForUrlPatterns(null, true, "/api/*");
    springSecurityFilter.addMappingForUrlPatterns(null, true, "/html/*");

    // Add the static content filter
    FilterRegistration.Dynamic staticContentFilter =
            container.addFilter("staticContentFilter", new StaticContentFilter());
    staticContentFilter.addMappingForUrlPatterns(null, true, "/static/*");
    staticContentFilter.addMappingForUrlPatterns(null, true, "/generated/*");

    // Add the logger filter
    FilterRegistration.Dynamic loggerFilter =
            container.addFilter("loggerFilter", new LoggerFilter());
    loggerFilter.addMappingForUrlPatterns(null, true, "/api/*");
    loggerFilter.addMappingForUrlPatterns(null, true, "/html/*");
  }
}

Is there anything obvious that I am missing? I've checked all the other questions/answers on this topic and didn't find a solution.

Carditis answered 4/4, 2014 at 19:45 Comment(5)
Have you turned on Spring's logging? What do it say?Salita
What's the easiest way to turn on Spring's logging?Carditis
With SLF4j, see here.Salita
Was able to turn on logging for Spring and it turned out to be a connection issue with one of the underlying databases. Once that was fixed the issue seems to be resolved. Thanks @SotiriosDelimanolisCarditis
codingpedia.org/ama/how-to-log-in-spring-with-slf4j-and-logbackJugoslavia
C
33

Setting an answer for this so others know what helped me in this particular situation. Turning on Spring logging allowed me to see that a database connection was in a hung state. Resolving the database issue allowed my application to finish deployment.

Carditis answered 7/4, 2014 at 16:8 Comment(4)
Resolved my problem too. I have a active query running on DB. Things got resolved nowGunfire
What is a hung state for a database connection ?Rahman
Thanks. It was database connection issue for me too.Mccloud
1. How did you turn on spring logging? 2.How did you resolve the hung database issue?Gutenberg
S
0

Had been trying to figure out this for a while.

The console got stuck at INFO: Initializing Spring DispatcherServlet 'dispatcherServlet'

Turns out that that was the last message and the service had already started. I was accessing the service on the wrong port.

Also, logging was not configured. So no logs showed up after the default output from spring.

Swaziland answered 27/3, 2019 at 9:52 Comment(0)
D
0

As I checked I had the same issue like Jive Application startup was stuck, my machine is designed with :

Configuration : 2 node with DB like i have eae,ingress-replicator & search on node 1 & node 2 have cache, docconverter . then two front node

Solution: checked that some services stuck after OS upgrade so i have rebooted all 4 nodes in sequence and the issue had solved.

Delocalize answered 28/11, 2020 at 14:26 Comment(0)
M
0

Sometimes it can also be a weird case where you've lost all prior logging, and this is the only remaining output you see, but the application is running. Verify what happens when you try to invoke the application.

For me, prior SFL4J output that I was used to suddenly got changed with a configuration change, and my final output line on the console was

Initializing Spring embedded WebApplicationContext

But the application was running. I was simply no longer seeing all the other logging that used to end with

2023-12-06 10:58:29.837 [main] INFO  MyApplication.logStarted(56) - Started MyApplication in 5.988 seconds (process running for 6.94)
Makalu answered 6/12, 2023 at 17:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.