Wednesday, December 11, 2019

Java.Lang.Classnotfoundexception: Org.Springframework.Web.Context.Contextloaderlistener [Solution]

Problem : You are getting java.lang.ClassNotFoundException : org.Springframework.Web.
Context.ContextLoaderListener inward your Spring-based Java Web application.
Cause: This fault comes when you lot are using Spring MVC framework inward your Java Web application as well as configured org.springframework.web.context.ContextLoaderListener equally a listener inward your deployment descriptor equally good known equally web.xml, but the JAR which contains this degree is non available inward spider web application's CLASSPATH.


This is a really of import degree inward Spring MVC framework, equally it is used to charge your boundary configuration files e.g. applicatoin-Context.xml as well as others, defined inward the context-param chemical portion of web.xml of your Java boundary spider web application, equally shown below :
    <context-param>         <param-name>contextConfigLocation</param-name>         <param-value>classpath:application-Context.xml</param-value>     </context-param>      <listener>         <listener-class>             org.springframework.web.context.ContextLoaderListener         </listener-class>     </listener> 



Approach : Like whatsoever other ClassNotFoundException error, you lot offset demand to abide by out the JAR file on which this degree is bundled as well as and thus add together that JAR into the appropriate place, e.g. WEB-INF/lib folder of your spider web application. So that the spider web application degree loader e.g. org.apache.catalina.loader.WebappClassLoader tin forcefulness out come across this JAR file. You tin forcefulness out come across inward below stack describe that it's the WebappClassLoader which failed to charge this degree :
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:1676)     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)     at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)     at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)     at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)     at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660)     at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)     at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)     at java.util.concurrent.FutureTask.run(FutureTask.java:138)     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)     at java.lang.Thread.run(Thread.java:662)


Solution :  It appears that the boundary context loader listener degree i.e. org.springframework.web.context.ContextLoaderListener  is moved to spring-web.jar since Spring 3.0. which way you lot should create next to fix java.lang.ClassNotFoundException : org.Springframework.Web.Context.ContextLoaderListener fault :


1. If you lot are using Spring version 3.0 as well as thus add together spring-web.jar into CLASSPATH i.e. exactly pose it within WEB-INF/lib folder.

2. If you lot are running inward Spring 2.0 or lower version as well as thus exactly add together spring.jar into your application's CLASSPATH, same exactly pose it within WEB-INF/lib directory.

3. If spring.jar or spring-web.jar is already inward CLASSPATH as well as thus your work is non due to JAR but due to wrongly configured classpath. See my ship service how to bargain alongside ClassNotFoundException to troubleshoot  further.

4. If you lot are using Maven the add together next dependency inward your pom.xml file :
         <dependency>             <groupId>org.springframework</groupId>             <artifactId>spring-web</artifactId>             <version>3.2.6.RELEASE</version>         </dependency> 


5. If you lot are getting java.lang.ClassNotFoundException : org.Springframework.Web.Context.ContextLoaderListener error In Eclipse as well as Tomcat, as well as thus you lot tin forcefulness out equally good effort next steps to brand certain maven dependencies are inward CLASSPATH as well as visible to Tomcat's spider web application degree loader. All you lot demand to create is add together maven dependencies into your eclipse project's spider web deployment assembly.
  • Select Project, Right click as well as select Properties.
  • Choose "Deployment Assembly".
  • Click the "Add..." push on the correct side.
  • Choose "Java Build Path Entries" from the carte du jour of directive type as well as click "Next".
  • Select "Maven Dependencies" from the Java Build Path Entries carte du jour as well as click "Finish".
You volition come across maven dependencies added to the spider web deployment assembly Definition past times now.

6. If  you are getting java.lang.ClassNotFoundException : org.Springframework.Web.Context.ContextLoaderListener error in previously working projection as well as you lot are certain that you lot non done anything which causes this fault as well as thus you lot tin forcefulness out try "Clean Tomcat Work Directory" or only "Clean..". This is supposed to discard all published country as well as republish from scratch.

Spring MVC books as well as resources
Spring Web Application Developer Certification

Thanks for reading this article thus far. If you lot similar this interview enquiry as well as thus delight percentage alongside your friends as well as colleagues. If you lot accept whatsoever enquiry or proposition as well as thus delight drib a comment as well as I'll effort to abide by an response for you.

Other mutual ClassNotFoundExceptions which comes inward Java programs :
  • General Guide to solve java.lang.ClassNotFoundException inward Java [guide]
  • How to solve java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver inward Java? [solution]
  • How to solve java.lang.ClassNotFoundException:org.Springframework.Web.Context.ContextLoaderListener [solution]
  • How to solve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver inward Java MySQL? [solution]
  • java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory? [solution]
  • How to connect to MySQL database from Java Program [steps]
  • How to fix java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver inward Java? [solution]
  • How to ready java.lang.ClassNotFoundException: org.postgresql.Driver fault inward Java? [solution]

P.S. - If you lot desire to larn how to educate RESTful Web Services using Spring Framework, cheque out Eugen Paraschiv's REST alongside Spring course. He has lately launched the certification version of the course, which is amount of exercises as well as examples to farther cement the existent globe concepts you lot volition larn from the course.

No comments:

Post a Comment