0

in my java maven project, I am getting an exception:

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

However, the maven pom eclipse, the build path libraries tab has spring-web-4.3.4.RELEASE.jar which contains that class, and is there because of the pom contains

 <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>${spring.version}</version>
    </dependency>

where

<spring.version>4.3.4.RELEASE</spring.version>

And that so the question is, why is that exception being thrown rather than that class being loaded?

esouser
  • 1
  • 1
  • 1

1 Answers1

0

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:

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)

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”.

enter image description here

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

enter image description here

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

enter image description here

The ContextLoaderListener is used to integrate Spring with other web application. Below is an example configuration in web.xml

<!-- file : web.xml --> 
 <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/Spring/applicationContext.xml</param-value>
  </context-param>

  <listener>
    <listener-class>
          org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>

And the common error message is, your server can not find this Spring ContextLoaderListener class during the server start up.

Try above fixes will help solve the issue.

More details here: https://howtodoinjava.com/spring-core/solved-java-lang-classnotfoundexception-org-springframework-web-context-contextloaderlistener/

Good to refer: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

Mebin Joe
  • 2,172
  • 4
  • 16
  • 22