Nicolas Richeton's blog

How to solve ‘Error listenerStart’ Error with Spring, Log4j and Tomcat

☕️ 1 min read
logo

Working with Spring, Log4j and Tomcat, you may have faced the following error, which prevents your web application to start :

Logs in french :

org.apache.catalina.core.StandardContext start GRAVE: Error listenerStart
org.apache.catalina.core.StandardContext start GRAVE: Erreur de démarrage du contexte [/mywebapp] suite aux erreurs précédentes

Logs in english :

org.apache.catalina.core.StandardContext start SEVERE: Error listenerStart
org.apache.catalina.core.StandardContext start SEVERE: Context [/mywebapp] startup failed due to previous errors

This error seems to come without any additional logs. Webapp startup is interrupted but you can start the application from the tomcat manager successfully.

The explaination for our case are :

  • We are using 2 context listeners : org.springframework.web.util.Log4jConfigListener and org.springframework.web.context.ContextLoaderListener.
  • Log4jConfigListener automatically sets a SYSTEM property : webapp.root to share the application context
  • On Tomcat, system properties are system-wide, thus are shared between applications
  • If 2 applications are installed, the webapp.root value is invalid for the second one, causing the exception

Solution : define a unique webAppRootKey value for each application.

<context-param>
<param-name>webAppRootKey</param-name>
<param-value>app1</param-value>
</context-param>

See : http://static.springsource.org/spring/docs/2.0.8/api/org/springframework/web/util/WebAppRootListener.html for additional information.

Note : Resin does not have this issue because it does not share system properties between webapps.