[Solved] java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

If you are working on a web application based on spring which requires use of org.springframework.web.context.ContextLoaderListener in web.xml file and you are getting this exception when you start the server. This exception is more likely when you are working on eclipse or possibly on other such IDE.

Exception log trace will look like this:

May 15, 2014 12:16:20 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:1714)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
	at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)
	at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514)
	at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:133)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

May 15, 2014 12:16:20 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
May 15, 2014 12:16:20 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
May 15, 2014 12:16:20 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/Spring4Struts2HibernateIntegration] startup failed due to previous errors
May 15, 2014 12:16:20 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
May 15, 2014 12:16:20 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
May 15, 2014 12:16:20 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 365 ms

exceptions-notes

Solution

Reason 1)

Possibly you have not added the spring web dependencies in your project. Just add them if you have not.

Reason 2)

If you are still getting this exception then you must add these dependencies to project deployment assembly as well.

To add dependencies in deployment assembly follow below instructions.

1) Open project properties and select Choose Deployment Assembly. Then select option “Java Build Path Entries”.

Deployment assembly option

2) Click Next and select all jar files. Click Finish.

Select all jars

3) Deployment assembly will look like this. Click Apply.

Apply deployment assembly

Above fixes will solve the issue.

Happy Learning !!

Was this post helpful?

Join 7000+ Fellow Programmers

Subscribe to get new post notifications, industry updates, best practices, and much more. Directly into your inbox, for free.

23 thoughts on “[Solved] java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener”

  1. You are a God thanks !!!!!, Worked !!! (if an anyone doesn’t work maybe its because yours Maven dependances was not downloaded correctly)

    Reply
  2. Solution 2 worked for me too.
    Just added the maven dependencies in the deployment assembly and then it started working. Thank you.

    Reply
  3. HI , after doing these steps still my problem not solved and i am getting this :-

    RESIN [11:10:28.419] WEB-INF/web.xml:20: com.caucho.server.webapp.ListenerConfig.setListenerClass(): 
    com.caucho.config.ConfigRuntimeException: java.lang.ClassNotFoundException: 
    org.springframework.web.context.ContextLoaderListener 
    (in EnvironmentClassLoader[web-app:production/webapp/default/ROOT,NEW])
    
    18:   <!--  Spring Listener -->
    19:   <listener>
    20:     <listener-class>
    21:       org.springframework.web.context.ContextLoaderListener
    22:     </listener-class>
    
    Reply
  4. Hi Lokesh, You have some amazing articles.
    One question, we have added the jars but can you explain why it is coming so as the errors are coming only during run time and not compile time ?. Should these jars be part of ONLY your application server or ONLY jar/ear or should be part of both ?

    Reply

Leave a Comment

HowToDoInJava

A blog about Java and its related technologies, the best practices, algorithms, interview questions, scripting languages, and Python.