1000Suns
1000Suns

Reputation: 207

Log4jConfigListener cannot be found -- context fails to start

I am trying to set up a Web application on Eclipse. I am using Tomcat 6.0 and JDK 1.6.0_23. For some unknown reason, I am getting this error:

SEVERE: Error configuring application listener of class org.springframework.web.util.Log4jConfigListener
java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4078)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
 at org.apache.catalina.core.StandardService.start(StandardService.java:519)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
 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)
Jan 24, 2011 11:44:08 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4078)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
 at org.apache.catalina.core.StandardService.start(StandardService.java:519)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
 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)

I checked if all libraries have been added to the build path, and everything seems to be correct. The log4j-1.2.15.jar is included and all the necessary Spring libraries.

I am very confused, especially to what causes the problem, as the project was working fine on another computer. Any help with this problem will be highly appreciated.

Naftal

Upvotes: 15

Views: 63974

Answers (7)

Reb0rN
Reb0rN

Reputation: 37

As you can see from the class name org.springframework.web.util.Log4jConfigListener is part of spring framework. And it was depricated since spring 4.2.1 . So check your spring version.

Upvotes: 0

cbbs
cbbs

Reputation: 71

Migrating to log4j2?

Don't forget to check your webapp/WEB-INF/web.xml (Web Application Deployment Descriptor) for extraneous Event Listener definitions.

Upvotes: 2

LakiGeri
LakiGeri

Reputation: 2105

If you use, log4j2, you can find these classes in

org.apache.logging.log4j.web.*

package.

Upvotes: 0

user3331355
user3331355

Reputation: 41

A simple solution is to clean the Tomcat directory in Eclipse. It worked for me.

Upvotes: 4

Templar
Templar

Reputation: 5135

Reticulogic's second suggestion is correct. However, in Eclipse Helios, the "Java EE Module Dependencies" option has been removed. The fix for Helios is as follows:

  1. Right click on your project in Eclipse and go to Properties-->Deployment Assembly
  2. Click "Add..."
  3. Select "Java Build Path Entries" and click "Next"
  4. select "Maven Dependencies" and click "Finish"

Upvotes: 43

Reticulogic
Reticulogic

Reputation: 31

If you are using maven and eclipse

1) Look in your web project .classpath file. If you have a classpath entry "org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER", then make sure the attribute is there as well.

<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>

2) If that does not work, then right click on your web project in eclipse and go to Properties-->JavaEE Module dependencies. Make sure the Maven Dependencies box is checked.

Then save, build deploy yada yada

Upvotes: 3

jamesmortensen
jamesmortensen

Reputation: 34038

The org.springframework.web.util.Log4jConfigListener class is definitely not in your classpath.

The first thing I would suggest is that you turn up the logging level in Tomcat -- in the conf folder -- to "ALL" or "DEBUG" so that you can see exactly what is going on in the container that is preventing this class from being found.

Second, I'd recommend you check your JAR files for the missing class file by running grep, if on linux/mac:

  # run at the root of your lib folders:
  grep -ri "org.springframework.web.util.Log4jConfigListener" *

The above command will return all JAR files that contain that package. Once the JAR file is isolated, then you can further troubleshoot.

Third, make sure you don't have any conflicts. Multiple versions of Log4j being in your classpath will wreak havoc. How is the system supposed to know which org.springframework.web.util.Log4jConfigListener package to load if there are 2 of them? Tomcat has 3 different classpath folders:

 shared/lib
 lib
 webapps/yourapp/WEB-INF/lib

Make sure you have only one log4j JAR file in only one of these folders.

Upvotes: 6

Related Questions