How To Bargain Alongside Java.Lang.Classnotfoundexception: Org.Springframework.Web.Servlet.Dispatcherservlet Inwards Confine Application

Advertisement

Masukkan script iklan 970x90px

How To Bargain Alongside Java.Lang.Classnotfoundexception: Org.Springframework.Web.Servlet.Dispatcherservlet Inwards Confine Application

Jumat, 27 Maret 2020

The java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet fault comes when yous deploy a Spring MVC application into Tomcat or Jetty too Servlet container non able to constitute this class, which commonly constitute inwards the spring-webmvc.jar file. The DispatcherServlet is the nub of Spring MVC framework, it implements the FrontController blueprint too intercept all HTTP requests sent to your Web application too after road it to right controller based upon URL mapping.


You demand to declare the DispatcherServlet inwards your web.xml too specify the URL blueprint thus that Servlet container similar Tomcat should shipping or road all HTTP asking to the configured DispatcherServlet.

We bring likewise laid load-on-startup tag equally 1 for this Servlet thus that it should endure loaded at the deployment time, rather than at the response fourth dimension when a telephone telephone for this Servlet comes.

In short, this DispatcherServlet is the link betwixt the Servlet Container too Spring MVC framework.

You tin farther banking concern jibe out Spring Framework 5: Beginner to Guru course on Udemy to larn to a greater extent than most how Spring MVC framework plant too why it's improve to purpose Spring MVC framework for developing Java Web application instead of simply using Servlet, JSP too JSF.

You tin encounter DispatcherServlet proclamation inwards deployment descriptor or web.xml file equally below:

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns="http://java.sun.com/xml/ns/javaee"  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"  id="WebApp_ID" version="3.0">   <display-name>Spring MVC HelloWorld</display-name>      <servlet>     <servlet-name>main</servlet-name>         <servlet-class>              org.springframework.web.servlet.DispatcherServlet         </servlet-class>         <load-on-startup>1</load-on-startup>    </servlet>     <servlet-mapping>         <servlet-name>main</servlet-name>         <url-pattern>/*</url-pattern>     </servlet-mapping> </web-app> 


For now, this diagram gives yous a practiced thought of an halt to halt the menstruation of how Spring MVC handles HTTP requests too what is the percentage of Dispatcher servlet in Spring MVC based Java application.

 fault comes when yous deploy a Spring MVC application into Tomcat or Jetty too Servlet con How to bargain alongside java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet  inwards Spring Application





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

When yous deploy a Java spider web application which uses Spring MVC into a spider web server similar Tomcat, it reads the deployment descriptor (web.xml file) too starts looking for org.springframework.web.servlet.DispatcherServlet inwards its classpath.

As per Java EE specification, all application dependency JARs must endure inwards WEB-INF/lib directory, thus if doesn't notice the JAR in that place it volition throw the java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet.

If yous are running your spider web application inwards Eclipse, yous tin nation Eclipse that it tin notice the Jars inwards additional place too non simply WEB-INF/lib.

Similarly, if yous are running spider web application inwards tomcat, it likewise loads JAR file from tomcat/lib, but yous must cry upward that when yous unload or reload a spider web app, it unloads all classes loaded from JAR file constitute inwards WEB-INF/lib but it doesn't unload classes from JAR loaded from tomcat/lib thus endure careful alongside that, equally multiple reload may throw java.lang.OutOfMemoryError: PermGen Space inwards Tomcat.

Here is how the stacktrace of this fault await like:

java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:142)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:663)
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1642)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)





The solution of java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet Error

The simplest solution of this employment is to banking concern jibe if yous the spring-mvc.jar inwards our classpath or not.

Depending upon the Spring MVC version similar 2.5, 3.0, 4.0 or 5.0, this shape is constitute inwards the spring-webmvc-2.5.2.jar file. Sometimes everything is likewise bundled inwards spring.jar, thus don't forget to banking concern jibe that.

If yous bring the projection configured inwards Eclipse thus yous tin likewise purpose the Eclipse shortcut Ctrl + T to notice out which shape file belong to which JAR file. Influenza A virus subtype H5N1 really useful fox piece troubleshooting ClassNotFoundException too NoClassDefFoundError inwards Java.


That's all most how to solve java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet Error inwards Spring based Java Application. As I said, simply banking concern jibe if yous bring spring-mvc.jar inwards your WEB-INF/lib directory or not. If no, thus simply add together that JAR file too this fault volition become away.


Further Reading
Spring Framework 5: Beginner to Guru
Spring Master Class - Beginner to Expert
solution]
  • java.net.SocketException: Failed to read from SocketChannel: Connection reset past times peer [fix]
  • Exception inwards thread "main" java.lang.ExceptionInInitializerError inwards Java Program [fix]
  • 2 ways to solve Unsupported major.minor version 51.0 fault inwards Java [solutions]
  • Fixing Unsupported major.minor version 52.0 Error inwards Java [solution]
  • java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver [solution
  • How to solve java.lang.UnsatisfiedLinkError: no ocijdbc11 inwards Java [solution]
  • java.lang.ClassNotFoundException: org.postgresql.Driver [fix]
  • java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet [fix]
  • java.io.IOException: Map failed too java.lang.OutOfMemoryError: Map failed  [fix]
  • java.net.BindException: Cannot assign requested address: JVM_Bind [fix]
  • Exception inwards thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 [solution]
  • org.hibernate.MappingException: Unknown entity Exception inwards Java [solution]
  • java.net.SocketException: Too many files opened upward java.io.IOException [solution]

  • P.S. - If yous desire to larn how to railroad train RESTful Web Service using Spring MVC inwards depth, I propose yous bring together the REST alongside Spring certification class past times Eugen Paraschiv. One of the best class to larn REST alongside Spring MVC.