Tomcat Spring Error with ContextLoaderListener: NoClassDefFoundError: org/apache/commons/logging/LogFactory

Today I going back to an old web application that contained a simple servlet.  I wanted to quickly add Spring to the project.  Since the project was not making use of Maven, I just put the necessary org.springframework.<module>-3.1.0.RELEASE.jar files in my WEB-INF/lib directory.

I then repackaged my project (created the WAR) and started Apache Tomcat (6.0.35).  I received this error:

Feb 16, 2012 11:10:03 AM org.apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
 at org.springframework.web.context.ContextCleanupListener.<clinit>(ContextCleanupListener.java:43)
 at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:144)
 at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4245)
 at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4886)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4750)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
 at org.apache.catalina.core.StandardService.start(StandardService.java:525)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
 ... 18 more

After some research, I found that Spring has an external logging dependency (discussed in the Spring Reference Manual).  To fix the error, I just downloaded commons-logging.jar and added it to my WEB-INF/lib directory.  Repackaged my project and restarted Tomcat.

No more error!  (And probably time to add Maven to the project too.)

Advertisements

About stevewall123

I am a Lead Software Engineer in Minneapolis working for Thomson Reuters. I am currently working on projects using Java, JavaScript, Spring, Drools, Hazelcast, Liquibase and Tomcat. Previously, I used C#, GWT, Grails, Groovy, JMS and JBoss Drools Guvnor. In the past I have worked on projects using J2EE, Swing, Webwork, Hibernate, Spring, Spring-WS, JMS, JUnit and Ant.
This entry was posted in Spring, Tomcat and tagged , . Bookmark the permalink.

2 Responses to Tomcat Spring Error with ContextLoaderListener: NoClassDefFoundError: org/apache/commons/logging/LogFactory

  1. Awani says:

    Hi. i m also facing the same error i.e. SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.security.openid.OpenIDAuthenticationFilter#0’: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/apache/http/client/ClientProtocolException
    and i do have commons-logging.jar in my WEB-INF/lib directory. Can plz suggest me anything to get it work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s