Eclipse - Java.Lang.Classnotfoundexception: Org.Springframework.Web.Servlet.Dispatcherservlet Inwards Tomcat

Problem : You are getting java.lang.ClassNotFoundException exception complaining that Spring's DispatcherServlet class is non available inwards the classpath. This fault is coming spell running a Spring MVC based Java application from Eclipse as well as Tomcat equally Server (running within Eclipse IDE itself). You receive got either included saltation framework JAR files manually yesteryear yourself or yous are using Maven to download as well as contend theme JAR files. Here is the stack describe of this fault :

java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:525)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:507)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:126)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1043)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4957



Cause of java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet

There are 2 original stimulate of getting java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet fault inwards Eclipse :


1) First, either yous don't receive got spring-webmvc-3.1.0.RELEASE.jar or like JAR, depending upon which Spring framework version yous are using e.g. Spring 4.0

2) Second is, Eclipse is non able to discovery this dependency inwards CLASSPATH.


But earlier going into those, let's outset understand
what is org.springframework.web.servlet.DispatcherServlet class? as well as why it is required?.

This flat is truly the forepart controller inwards Spring MVC framework, all HTTP requests become via this flat to dissimilar controller classes. You define this flat to map against a URL blueprint inwards the web.xml file using load-on-startup tag, that's why yous run across that loadOnStartup() call on stack trace of this error. 


This is why when yous deploy your Spring MVC based spider web application inwards Tomcat, the WebAppClassLoader search for org.springframework.web.servlet.DispatcherServlet flat inwards flat loader's CLASSPATH, which is WEB-INF/lib folder of your Java Web application.


If it doesn't flora this flat within whatsoever JAR file inwards WEB-INF/lib, it throws java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet.


If yous are novel to Spring, yous tin sack equally good receive got a hold back at Spring inwards Action book, 1 of the improve books to larn basics of Spring framework as well as Spring MVC together. The 4th edition of this mass equally good covers Spring 4.

 This fault is coming spell running a Spring MVC based Java application from Eclipse as well as T Eclipse - java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet inwards Tomcat


Now let's run across how to solve this problem.



How to Fix java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet inwards Tomcat as well as Eclipse

Here are about steps yous tin sack receive got to bargain amongst this fault inwards Tomcat within Eclipse IDE :

1) If yous are using Maven as well as if spring-webmvc is non added equally a dependency inwards your project's pom.xml as well as hence delight add together that. Once yous produce that, construct your projection using mvn install or mvn build. This volition download saltation MVC JAR files as well as about other dependency.


2) The instant measuring is to add together Maven Dependency into deployment assembly. This is required to motion all theme JAR files into WEB-INF/lib directory of Java spider web application.

In social club to add together Maven Dependency into deployment assembly inwards Eclipse, follow below steps :

i) Right-click your project, select properties as well as select Deployment Assembly.

 This fault is coming spell running a Spring MVC based Java application from Eclipse as well as T Eclipse - java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet inwards Tomcat


ii)  Now click Add as well as select Java Build Path Entries as well as select Maven dependency theirs. If your projection is non laid for the automatic construct as well as hence only refresh the projection as well as construct it.

Now yous should move able to run your Spring MVC application inwards attached Tomcat from Eclipse IDE itself.

3) If this doesn't laid upwards your occupation as well as hence produce a Maven clean, followed yesteryear Maven construct to regenerate WAR file.


That's all virtually how to laid upwards java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet fault inwards Eclipse as well as Tomcat. It's equally good possible that yous acquire this fault exterior Eclipse IDE when yous are deploying your WAR file inwards about other environment. That fourth dimension yous must cheque whether relevant JAR file e.g. spring-webmvc-3.1.0.RELEASE.jar exists inwards either WEB-INF/lib directory of your application or Tomcat/lib directory. It's improve to continue inwards WEB-INF/lib directory because when yous undeploy all the classes loaded yesteryear WebAppClassLoader are eligible for garbage collection, which is non the representative for JAR files loaded from Tomcat's lib directory. That tin sack stimulate PermGen Memory leak inwards Tomcat.

Further Reading
Spring Framework 5: Beginner to Guru
Spring Master Class - Beginner to Expert
Introduction to Spring MVC 4 By Bryan Hansen
Spring as well as Hibernate for Beginners
Spring inwards Action 4th edition yesteryear Craig Walls

P.S. - If yous desire to larn how to educate RESTful Web Service using Spring MVC inwards depth, I advise yous bring together the REST amongst Spring certification class yesteryear Eugen Paraschiv. One of the best course of written report to larn REST amongst Spring MVC. 

Belum ada Komentar untuk "Eclipse - Java.Lang.Classnotfoundexception: Org.Springframework.Web.Servlet.Dispatcherservlet Inwards Tomcat"

Posting Komentar

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel