java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
Asked Answered
C

35

311

I included these in the Build Path:

  • all Spring libs
  • Apache Tomcat 7.0 library

The project still fails during startup:

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:1676)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Jun 2, 2011 11:07:38 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class org.springframework.web.context.request.RequestContextListener
java.lang.ClassNotFoundException: org.springframework.web.context.request.RequestContextListener
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Jun 2, 2011 11:07:38 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class com.sun.faces.config.ConfigureListener
java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

In org.sprintframework.web-3.1.0.M1.jar, I can see the org.springframework.web.context.ContextLoaderListener.

Someone on Google says that spring.jar should be included but I don't see any spring.jar in 3.x distribution.

Eclipse 3.6.2
Tomcat 7

Edit: Someone on the Spring Forum (offline) said "Automatically update dependencies" should be checked in Project Properties but I don't see anything like that in project properties.

Commonable answered 2/6, 2011 at 5:23 Comment(3)
close the project , create new workplace, make assure about the dependencies in POM. i had to face this problem but was fixed after correction in dependenciesSimulacrum
Can you post the contents of your .war /lib folder please. Or at least everything that is .*spring.*\.jar.Donnelly
Even if I added the following dependency to pom, i was still having the same error. <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>{Spring-Version}</version> </dependency> What i did was as others suggested i added the maven dependencies to the deployment assembly. And When I update the pom with other dependencies and doing maven > update project, the error keeps coming. Inspecting the deployment assembly shows me maven dependencies are getting kicked out. I had to redo the above process again.Exhibition
S
818

I had a similar problem when running a spring web application in an Eclipse managed tomcat. I solved this problem by adding maven dependencies in the project's web deployment assembly.

  1. Open the project's properties (e.g., right-click on the project's name in the project explorer and select "Properties").
  2. Select "Deployment Assembly".
  3. Click the "Add..." button on the right margin.
  4. Select "Java Build Path Entries" from the menu of Directive Type and click "Next".
  5. Select "Maven Dependencies" from the Java Build Path Entries menu and click "Finish".

You should see "Maven Dependencies" added to the Web Deployment Assembly definition.

Sewell answered 14/11, 2011 at 21:19 Comment(17)
That is the way you should do it, the correct way in eclipse.Heresiarch
I was having the same problem. But I cannot see 'Deployment Assembly' at 'Properties' (in a module of my multimodule maven project).Moncear
This is correct, although highly annoying. Perhaps something m2e plugin should take care of, in my opinion.Excrescent
or add M2_REPO into build path, which points to your .m2/repositoryDisconnect
I was getting this error while the Maven Dependencies were part of the build. Chepech's solution below worked.Butanol
This also worked for an Ivy project (selecting ivy.xml as the last step.)Chindwin
I see Maven Dependencies added to the Web Deployment Assembly definition but I keep getting the error.Undo
The actual solution for me was to install the "m2e-wtp - Maven integration for WTP". This solution gave me a NullPointerException.Amenity
What if Java Build Path Entries contains nothing ? I'm in that case.Ballyrag
This issue reoccurs for me repeatedly. Is there a permanent fix?Dowie
respect :) how did you know it?Nijinsky
@Sewell How to do this in IntelliJ IDEA?Weiss
Reading through the comments and answers, I feel that the main issue is that the Maven dependency (the Spring lib) cannot be found. Usually it occurred when you forgot to add Maven libs to build path (like this answer) or you have some changes in pom.xml and *Maven libs are not updated". If it is the later case, it's best to run "Maven > Update project"Disconnect
This is the best answer. A Maven project doesn't consider normal build path export tab settings. We need to use deployment assembly to move maven dependencies to the WEB-INF/lib directoryBingle
What if we don't use Maven ?Exempt
The option "Deployment Assembly" does not exist under my properties, why is that?Impassible
just after found the solution , I saw this answer that is what we need , on "Deployment Assembly" add "java build path entries"Spiculate
T
126

Same thing happens to me from time to time when using Eclipse WDT. Its specialy frustrating when this happens to a unmodified and previously working project. This is what I do to fix it in this last scenario:

  1. Stop Tomcat (if it's running)
  2. Open the "Servers" view: Window > Show view > Other > Server > Servers
  3. Right Click on Tomcat Server > Clean Tomcat Work Directory.
  4. Right Click on Tomcat Server > Clean
  5. Restart the server

This usually fixes the issue you mention.

Tsarina answered 5/9, 2012 at 21:41 Comment(6)
There is a bug report for that specific situation (bugs.eclipse.org/bugs/show_bug.cgi?id=365748). Eclipse developers are in need of more informations about it and ways to reproduce the problem.Format
good this is the flexible solution for all, this answer must be marked as answer. Good work ChepechPodiatry
This is really a simplest solution for this problem. Thanks Chepech!Asset
This did not help for me using eclipse 4.4. I had to use Susie's method remove/add deployment to tomcat. I was monitoring the tomcat deployment folder when performing the cleanings. Don't know why cleaning does not clean the the deployment folder.Riff
Did you tried manually cleaning it? the whole trick of this method is about the Catalina work folder clean up.Tsarina
Deployment assembly is the right way to do it, but if it doesn't work due to some corruption or whatnot, this cleanup actually fixes it.Produce
N
29

I used IntelliJ IDEA, compilation is successful, but when starting Tomcat, it says:

Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

In the beginning, I thought the JAR was missing, but it was in place.

Solution: File > Project Structure > Artifacts, in the Output Layout double click in right panel Available Elements the library named like Maven:..., it will be moved to WEB-INF/lib in the left pane.

Accept and restart Tomcat.

Nicolasanicolau answered 29/12, 2015 at 11:58 Comment(2)
This answer is not exactly relevant for the asked question as OP was using EclipseHarsh
But it helped me.Goldenrod
I
27

You could try "Clean Tomcat Work Directory" or simply "Clean..". This supposed to discard all published state and republish from scratch.

Incrust answered 16/4, 2012 at 6:21 Comment(1)
Thx for this solution! The accepted answer above didn't solve this issue for me, but yours did.Olivann
R
8

This is surely Eclipse related issue. The thing which worked for me is creating a new server in eclipse server tab. Then run your application in this new server, it should work.

Revengeful answered 12/12, 2012 at 11:12 Comment(0)
Z
7

If you're using maven, perhaps the project aint built yet. First do a mvn clean package then try redeploying again.

Zulema answered 2/6, 2011 at 6:6 Comment(0)
B
7

You have to use at least version 3.2.8.RELEASE of spring-core.

For Maven, set in your pom.xml:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>3.2.8.RELEASE</version>
</dependency>

Source: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/cglib/core/SpringNamingPolicy.html, since 3.2.8.

Bonney answered 1/9, 2014 at 20:14 Comment(0)
A
7

If everything mentioned above does not work try the following. It worked for me.

Remove your project from the server > Restart server > Add your project to server > Restart server.

Detailed Instruction:

1. Right click on server > Add and Remove
2. Select your project > Remove > Finish
3. Restart your server
4. Right click on server > Add and Remove
5. Select your project > Add > Finish
6. Restart your server again.
Aalst answered 2/9, 2014 at 20:51 Comment(0)
G
6

I was facing the same issue for a eclipse project configured for Tomcat 7 runtime

Right click on project and go to project properties. Click on Deployment Assembly. I could notice that my spring library jars which I created during compile time with a user library was missing. Just add the jars and you should see no errors in console during tomcat start up

Glassman answered 7/10, 2012 at 18:47 Comment(0)
C
6

Solution for Eclipse Luna:

  1. Right Click on maven web project
  2. Click 'Properties'menu
  3. Select 'Deployment Assembly' in left side of the popped window
  4. Click 'Add...' Button in right side of the popped up window
  5. Now appear one more popup window(New Assembly Directivies)
  6. Click 'Java Build path entries'
  7. Click 'Next' Button
  8. Click 'Finish' Button, now atomatically close New Assemby Directivies popup window
  9. Now click 'Apply' Button and Ok Button
  10. Run your webapplication
Consternation answered 19/12, 2014 at 5:57 Comment(0)
I
5

If you are using IntelliJ IDEA, and deploy application on Tomcat Server, it says: Under

  1. File menu ->
  2. Select project Structure ->
  3. Click artifact then Output Layout->
  4. Select your jars on the right, double click it
  5. Now its in the left pane in WEB\lib ->
  6. Restart server

enter image description here

Isma answered 27/10, 2017 at 20:7 Comment(1)
worked for me, just not clear stepsZared
C
3

Actually this is a problem of Tomcat. Just go to 'lib' folder of your project and copy your all 'Spring' related jars into this. Refresh your project and you are all good to go. This problem sometime persists because tomcat is unable to locate Spring core classes.

Corum answered 5/12, 2015 at 6:19 Comment(1)
where is located the "lib" folder?Galoot
D
2

For me the fix was to right click on my webapp module > Maven > Update Project

Diplostemonous answered 5/5, 2015 at 13:23 Comment(0)
S
2

I also had the same error. I had not added the below dependency in my POM file.

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.1.7.RELEASE</version>
  </dependency>

But My porject used to run even before I had added this dependency. But at one point it stopped and started giving the same above error.

If any one couldn't solve this error they can also solve by this link

Spasm answered 3/11, 2015 at 11:32 Comment(1)
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.1.6.RELEASE</version> </dependency> Adding this helped me getting solved this error .Lamee
C
2

I had the same issue. I resolved it by adding spring-web dependency in my pom. Make sure you use spring-web jar which has ContextLoaderListener class extends ContextLoader implements ServletContextListener and reside in the package org.springframework.web.context. I used 3.0.4.RELEASE

Calcification answered 27/8, 2017 at 8:45 Comment(0)
S
1

I tried the

  • project clean mvn
  • clean
  • clean tomcat work directory Automatically
  • update dependencies

The only thing that worked at least temporarily was to add Maven Dependencies to Web Deployment Assembly definition

But this does not work for ever! After a couple of days it stops working. My solution was to remove Maven Dependencies, apply change and add Maven Dependencies again.

I'm using - eclipse Juno - embedded maven - tomcat 7

Streptokinase answered 25/1, 2013 at 10:50 Comment(0)
C
1

For gradle users, It works with following steps

1) Stop and Delete tomcat server from Servers Tab in eclipse

eclipse tomcat tab

2) clean webapp and work directory from tomcat installation , (Reference, How-To: Clear out Tomcat’s cache and fix outdated JSP problems)

$ rm -r /usr/local/AT7028/work/*
$ rm -r /usr/local/AT7028/webapps/WAR_NAME

3) clean and eclipsify project using build tool

$ ./gradlew clean eclipse //fire respective command for mvn users, $ mvn clean package

4) configure a new Tomcat server in eclipse, and run the project again.

Catima answered 28/8, 2013 at 11:8 Comment(0)
L
1

i too faced the same problem.... and resolved by following the below steps:

RC(right click on web project) --> properties --> Deployment Assembly --> Add --> Java Build Path Entries --> Next --> select jar files which are missing --> next --> finish

Application is running successfully...

Leeuwarden answered 8/12, 2013 at 16:37 Comment(1)
I have the OP's error, but there were no jar files missing in my deployment assembly.Orthogenesis
R
1

I have the same issue , and I have resolved it using the steps mentioned above.but no when I have this issue again and i try the following,

RC(right click on web project) --> properties --> Deployment Assembly --> Add --> Java Build Path Entries --> Next -->

after clicking on next its only a blank window with the options Next and Fnish disabled.What can I do now?

Rottweiler answered 27/1, 2015 at 5:18 Comment(0)
C
1

I faced the same problem.

Just removed the server from configuration and added it back after restarting eclipse by adding it to the server runtime environment.

Champerty answered 2/5, 2015 at 17:58 Comment(0)
L
1

One quick solution I prefer which I suited most for this situation is simply delete .metadata folder of your work space and import your projects again. If you try all other option it wont guarantee the success. Sometimes the above solutions work sometime you will spend your precious hours to fix this configuration.

One day i decided to clean my work station.I arranged the projects to their suitable folders according to different clients. As a result all got messed up. After spending a whole day it did not end up in a fixed work space. Next day I simply deleted the .metadata folder of the work space and imported all the projects again. Bingo all set.

Leroi answered 5/7, 2016 at 10:59 Comment(0)
A
1

Put <packaging>war</packaging> in your pom.xml if you are using Maven. In that case, maybe it is with jar packaging

You must have Maven libs in Deployment Assembly

Atp answered 15/7, 2016 at 13:45 Comment(0)
A
1

I ran into this a couple times a quarter. This time I had a minimal change summary in my git diff and tracked the problem to a reset classpath (missing my WEB-INF/lib dependency) in eclipse. This seems to occur any time I pull in or pull out parent/sibling maven projects.

There are mentions of adding your spring jars to the tomcat web container lib - this is ok and is the way most EE servers run. However be aware that by placing spring higher in the classloader tree on tomcat you will be running higher than the classloader level of your war context. I recommend you leave the libs in a per/war lower level classloader.

We see the following after a truncated .classpath after a structural project change in eclipse.

Dec 18, 2016 11:13:39 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class org.springframework.web.context.request.RequestContextListener
java.lang.ClassNotFoundException: org.springframework.web.context.request.RequestContextListener

My classpath was reset and the WEB-INF/lib dependency was removed.

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

put back

<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>

and you will be OK.

thank you /michael

Alfredoalfresco answered 21/12, 2016 at 22:11 Comment(1)
exactly, this happens when , <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> disappeas from .classpath fileSpiculate
P
0

Using the "Update project configuartion" messed up the build path of the project.

Fix: Open the "configure build path..." menu (right click on the project) and fix the Included/Excluded options for each source folder. That worked for me.

Performance answered 27/7, 2013 at 1:31 Comment(0)
L
0

In many case It is java facet problem ,jdk or jre or jsp version is difference than maven project face.

Laresa answered 25/9, 2013 at 17:31 Comment(0)
A
0

The actual solution for me was to install the "m2e-wtp - Maven integration for WTP". The solution of Marcelo is not neccessary in that case.

Amenity answered 22/10, 2014 at 13:55 Comment(0)
M
0

if nothing from above works, remove the .class from the listener class i.e.

<listener>
<listener-class>

org.springframework.web.context.ContextLoaderListener.class

</listener-class>
</listener>
Misadventure answered 6/6, 2015 at 1:39 Comment(0)
B
0

This works for me ..

Right Click on maven web project Click 'Properties'menu Select 'Deployment Assembly' in left side of the popped window Click 'Add...' Button in right side of the popped up window Now appear one more popup window(New Assembly Directivies) Click 'Java Build path entries' Click 'Next' Button Click 'Finish' Button, now atomatically close New Assemby Directivies popup window Now click 'Apply' Button and Ok Button Run your webapplication

Burress answered 5/6, 2016 at 3:14 Comment(0)
A
0

This happened to me after I made changes to my Hibernate mapping in an IntelliJ project using Gradle. Simply rebuilding the project worked for me.

Arzola answered 30/11, 2016 at 14:12 Comment(0)
J
0

I got this when I had the lib in my build path, but not in my deployment assembly. Also when I had a missing context.xml.

Jacobsohn answered 30/1, 2017 at 3:31 Comment(0)
M
0

When I look at the solutions, it seems the problem is always something that prevents the spring library to be loaded. It could be a dependency problem or a deployment problem.

In my case, it was the maven repository that somehow got corrupt. What solved the problem was to remove the folder `C:\Users(my name).m2\repository' and rebuild.

Monograph answered 8/5, 2019 at 12:28 Comment(0)
I
0

In my case the problem was that the class was located in test package. Moving it to main package has solved the problem.

Inconvenience answered 4/7, 2019 at 13:15 Comment(0)
H
0

I did a code pull but did not update project version on eclipse server/modules tab. For some reason, maven clean install did not delete old project folder from target and instead created new folder too.

Correcting project version on server fixed this issue.

Posting this just in case someone makes the same mistake.

Highroad answered 19/9, 2019 at 16:2 Comment(0)
K
0

Check also the scope in the pom.xml dependency , if the scope is provided that indicates you expect the JDK or a container to provide the dependency at runtime.

For more details: Dependency Scope

Katinka answered 29/8, 2021 at 14:58 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.