Senin, 23 Juni 2014

Spring - java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener Quick Solution




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:









<context-param>


    <param-name>contextConfigLocationparam-name>


    <param-value>


        /WEB-INF/applicationContext.xml


       
/WEB-INF/spring-security-setup.xml


    param-value>


context-param>


<listener>


   <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-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"



java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener  cause and solutionReal cause of this exception is that ClassLoader,
which is loading this application (could be web-app class loader, if you are
running on Tomcat
server
) is not able to find class
"org.springframework.web.context.ContextLoaderListener" but
manifestation and trigger could vary from one case to another. Here is list of
some possible causes of
java.lang.ClassNotFoundException:
org.springframework.web.context.ContextLoaderListener
in Spring
MVC application :





1) If you are running with Spring 3.0 or greater and don't have spring-web.jar in your Classpath.





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 Javarevisited Blog






How to
resolve java.lang.UnsupportedClassVersionError with example























Source:http://javarevisited.blogspot.com/2013/01/spring-javalangclassnotfoundexception-springframeworkwebcontextloaderlistener.html

Tidak ada komentar:

Posting Komentar