Error configuring application listener of class ContextLoaderListener Solution

(62 Views)


Problem:

The ContextLoaderListener class is used to integrate Spring framework with other web application

<!-- it is web.xml file --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/Spring-Config/applicationContext.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.content.ContextLoaderListener </listener-class> </listener>

Exception Stack Trace:

SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException: Caused by: org.springframework.web.context.ContextLoaderListener at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3915) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467) 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:443) 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(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
      

Solution:

This happens both in debugging and deployment environment.

1.Deployment environment

In deployment environment, you to make sure that your server classpath has the Spring jar library (e.g spring 3.0 jar).

For Spring 5, ContextLoaderListener is moved to spring-web.jar, you can get the library from Maven central repository.

add maven dependency for spring-web.jar

<!-- https://mvnrepository.com/artifact/org.springframework/spring-web --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>5.0.8.RELEASE</version> </dependency>

2.Debugging environment

In debugging environment, the steps may differ from one IDE to another IDE, but the solution is same. In Eclipse, developers usually use a tomcat or jboss server for debugging, just cross chack that correct Spring jars are included.

1. Double click on your server

2. Open launch configuration to access the server environment

Image of web.xml

3. Click on the classpath tab

4. Include the Spring jar file here, sometimes common log jar is also required due to Spring dependency.

Image of web.xml

5. Done, run your application again. You will not get that exception again.

Solution Worked 0 UpvotesUpvote

        

Solution Didn't Worked 0 DownvotesDownvote



Comments



Search