If you have worked in Spring MVC than you may be familiar with
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener,
which is common problem during deployment. Spring MVC throws java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener ,
when its not able to find org.springframework.web.context.ContextLoaderListener class which is used to load spring MVC configuration files like application-context.xml and other Spring Framework configuration files defined in context-param element of web.xml in an Spring MVC web application as:
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener,
which is common problem during deployment. Spring MVC throws java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener ,
when its not able to find org.springframework.web.context.ContextLoaderListener class which is used to load spring MVC configuration files like application-context.xml and other Spring Framework configuration files defined in context-param element of web.xml in an Spring MVC web application as:
<!-- spring mvc setup -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/spring-security-setup.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
I have touched base on this exception in my earlier article how
to resolve ClassNotFoundException in Java and we will discuss this in
detail here. In this Java debugging tutorial, we will find some common reasons
of java.lang.ClassNotFoundException:
org.springframework.web.context.ContextLoaderListener and quick
fix or solution.
Cause of "java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener"
2) If you are on spring 2.0 or lower than check spring.jar in your
classpath.
3) If spring.jar or spring-web.jar is in classpath
than check your user running Java or Tomcat has permission to read those JAR
files, possible cause in unix or linux operation system.
4) If its coming on Eclipse with Maven then check whether maven
dependencies related to spring-web.jar is included in your build path. If it’s
included than just try to build the project using maven install, this will
download all dependency. You can verify that whether relevant spring
dependencies are included or not by checking Maven Dependencies in project node.
Solution of java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
Here are possible and quick solution to fix this exception in Spring MVC
application:
1) Include spring.jar if you are running on spring 2.0 or
include spring-web.jar for spring 2.5, 3.0 and greater.
2) If you are running on Tomcat server than include above JAR in WEB-INF/lib folder
3) In case of Eclipse
and maven include maven dependency on build path.
4) If you are running Tomcat inside Eclipse than cleaning Tomcat work
directory and restarting server also helps. You can clean Tomcat work directory
by right clicking Tomcat server node in Eclipse
and selecting “Clean Work Directory” and “Clean” option.
These usually fix java.lang.ClassNotFoundException:
org.springframework.web.context.ContextLoaderListener in Spring
MVC Application. If you still face issue than let us know and we will try to
help you finding root cause of org.springframework.web.context.ContextLoaderListener
and Fixing it.
Other Java debugging Tutorials from Learn About Linux Blog
How to
resolve java.lang.UnsupportedClassVersionError with example
No comments:
Post a Comment