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

<div dir&equals;"ltr" style&equals;"text-align&colon; left&semi;" trbidi&equals;"on">When we deploy a Spring MVC application into Tomcat and Servlet container not able to found this class <b>org&period;springframework&period;web&period;servlet&period;DispatcherServlet<&sol;b> then an Exception <b>java&period;lang&period;ClassNotFoundException&colon; org&period;springframework&period;web&period;servlet&period;DispatcherServlet<&sol;b> error comes which usually found in the <b>spring-webmvc&period;jar<&sol;b> file&period;<&sol;p>&NewLine;<div align&equals;'center' id&equals;"ads-id"><&sol;div>&NewLine;<p>The DispatcherServlet is the core of Spring MVC framework&comma; In Spring’s web MVC framework the mechanism of dispatching the request to the appropriate controllers is achieved by configuring the DispatcherServlet class&period; DispatcherServlet is the class which manages the entire request handling process&period;Like a normal servlet DispatcherServlet also needs to be configured in the web deployement Descriptor&lpar;web&period;xml&rpar; and specify the URL pattern such that Servlet container like Tomcat should send all HTTP request to DispatcherServlet&period; We also set load-on-startup tag as 1 for this Servlet&comma; so that it should be loaded at deployment time&period; This Servlet is the link between Servlet Container and Spring MVC framework&period; <&sol;p>&NewLine;<div style&equals;"background-color&colon; &num;f2f9fc&semi; border&colon;1px solid &num;c9e6f2&semi;border-radius&colon;3px&semi;padding&colon;16px&semi;line-height&colon;1&period;45&semi;"><b>Popular Tutorials<&sol;b><&sol;p>&NewLine;<ul style&equals;"text-align&colon; left&semi;">&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2012&sol;06&sol;spring-30-baby-step-to-learn&period;html"><em><strong>Spring Tutorial<&sol;strong> <&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2012&sol;12&sol;spring-web-mvc-framework-chapter-38&period;html"><strong><em>Spring MVC Web Tutorial <&sol;em><&sol;strong><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2016&sol;06&sol;introduction-to-spring-boot-a-spring-boot-complete-guide&period;html"><em><strong>Spring Boot Tutorial<&sol;strong> <&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2013&sol;02&sol;spring-security-take-baby-step-to-secure&period;html"><em>Spring Security Tutorial<&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2012&sol;07&sol;introduction-to-aop-in-spring&period;html"><em>Spring AOP Tutorial<&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2012&sol;12&sol;using-spring-jdbc-framework-chapter-32&period;html"><em>Spring JDBC Tutorial<&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2017&sol;01&sol;spring-hateoas-hypermedia-driven-restful-web-service&period;html"><em><strong>Spring HATEOAS <&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2017&sol;01&sol;microservices-with-spring-boot&period;html"><em><strong>Microservices with Spring Boot<&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2013&sol;06&sol;jax-rs-web-service-tutorial&period;html"><strong><em>REST Webservice<&sol;em> <&sol;strong><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2013&sol;01&sol;core-java-baby-step-to-be-best-java-ian&period;html"><em><strong>Core Java <&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2012&sol;03&sol;hibernate-3-on-baby-steps&period;html"><em><strong>Hibernate Tutorial<&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2012&sol;12&sol;spring-batch-process-with-example&period;html"><strong><em>Spring Batch<&sol;em> <&sol;strong><&sol;a><&sol;b><&sol;li>&NewLine;<&sol;ul>&NewLine;<&sol;div>&NewLine;<p><b>DispatcherServlet in the deployment descriptor &lpar;web&period;xml&rpar;<&sol;b><&sol;p>&NewLine;<pre class&equals;"highlight" name&equals;"code">&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"UTF-8"&quest;&gt&semi;&NewLine;&lt&semi;web-app version&equals;"2&period;5" xmlns&equals;"http&colon;&sol;&sol;java&period;sun&period;com&sol;xml&sol;ns&sol;javaee"&NewLine;xmlns&colon;xsi&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;XMLSchema-instance"&NewLine;xsi&colon;schemaLocation&equals;"http&colon;&sol;&sol;java&period;sun&period;com&sol;xml&sol;ns&sol;javaee http&colon;&sol;&sol;java&period;sun&period;com&sol;xml&sol;ns&sol;javaee&sol;web-app&lowbar;2&lowbar;5&period;xsd"&gt&semi;&NewLine; &lt&semi;servlet&gt&semi;&NewLine; &lt&semi;servlet-name&gt&semi;dispatcher&lt&semi;&sol;servlet-name&gt&semi;&NewLine; &lt&semi;servlet-class&gt&semi;org&period;springframework&period;web&period;servlet&period;DispatcherServlet&lt&semi;&sol;servlet-class&gt&semi;&NewLine; &lt&semi;load-on-startup&gt&semi;2&lt&semi;&sol;load-on-startup&gt&semi;&NewLine; &lt&semi;&sol;servlet&gt&semi;&NewLine; &lt&semi;servlet-mapping&gt&semi;&NewLine; &lt&semi;servlet-name&gt&semi;dispatcher&lt&semi;&sol;servlet-name&gt&semi;&NewLine; &lt&semi;url-pattern&gt&semi;&ast;&period;html&lt&semi;&sol;url-pattern&gt&semi;&NewLine; &lt&semi;&sol;servlet-mapping&gt&semi; &nbsp&semi;&NewLine;&lt&semi;&sol;web-app&gt&semi;&NewLine;<&sol;pre>&NewLine;<p>&NewLine;<b>Reason of java&period;lang&period;ClassNotFoundException&colon; org&period;springframework&period;web&period;servlet&period;DispatcherServlet<&sol;b><br &sol;>&NewLine;<b><br &sol;>&NewLine;<&sol;b> When we deploy a Java web application which uses Spring MVC into a web server like Tomcat&comma; it reads the deployment descriptor &lpar;web&period;xml file&rpar; and starts looking for org&period;springframework&period;web&period;servlet&period;DispatcherServlet in its classpath&period; As per Java EE specification&comma; all application dependency JARs must be in WEB-INF&sol;lib directory&comma; so if doesn&&num;8217&semi;t find the JAR there it will throw the java&period;lang&period;ClassNotFoundException&colon; org&period;springframework&period;web&period;servlet&period;DispatcherServlet&period;<&sol;p>&NewLine;<p><b>Error stacktrace of this issue like<&sol;b>&colon;<&sol;p>&NewLine;<p>java&period;lang&period;ClassNotFoundException&colon; org&period;springframework&period;web&period;servlet&period;DispatcherServlet<br &sol;>&NewLine;at org&period;apache&period;catalina&period;loader&period;WebappClassLoader&period;loadClass&lpar;WebappClassLoader&period;java&colon;1702&rpar;<br &sol;>&NewLine;at org&period;apache&period;catalina&period;loader&period;WebappClassLoader&period;loadClass&lpar;WebappClassLoader&period;java&colon;1547&rpar;<br &sol;>&NewLine;at org&period;apache&period;catalina&period;core&period;DefaultInstanceManager&period;loadClass&lpar;DefaultInstanceManager&period;java&colon;532&rpar;<br &sol;>&NewLine;at org&period;apache&period;catalina&period;core&period;DefaultInstanceManager&period;loadClassMaybePrivileged&lpar;DefaultInstanceManager&period;java&colon;514&rpar;<br &sol;>&NewLine;at org&period;apache&period;catalina&period;core&period;DefaultInstanceManager&period;newInstance&lpar;DefaultInstanceManager&period;java&colon;142&rpar;<br &sol;>&NewLine;at org&period;apache&period;catalina&period;core&period;StandardWrapper&period;loadServlet&lpar;StandardWrapper&period;java&colon;1144&rpar;<br &sol;>&NewLine;at org&period;apache&period;catalina&period;core&period;StandardWrapper&period;load&lpar;StandardWrapper&period;java&colon;1088&rpar;<br &sol;>&NewLine;at org&period;apache&period;catalina&period;core&period;StandardContext&period;loadOnStartup&lpar;StandardContext&period;java&colon;5176&rpar;<br &sol;>&NewLine;at org&period;apache&period;catalina&period;core&period;StandardContext&period;startInternal&lpar;StandardContext&period;java&colon;5460&rpar;<br &sol;>&NewLine;at org&period;apache&period;catalina&period;util&period;LifecycleBase&period;start&lpar;LifecycleBase&period;java&colon;150&rpar;<br &sol;>&NewLine;at org&period;apache&period;catalina&period;core&period;ContainerBase&period;addChildInternal&lpar;ContainerBase&period;java&colon;901&rpar;<br &sol;>&NewLine;at org&period;apache&period;catalina&period;core&period;ContainerBase&period;addChild&lpar;ContainerBase&period;java&colon;877&rpar;<br &sol;>&NewLine;at org&period;apache&period;catalina&period;core&period;StandardHost&period;addChild&lpar;StandardHost&period;java&colon;633&rpar;<br &sol;>&NewLine;at org&period;apache&period;catalina&period;startup&period;HostConfig&period;deployDescriptor&lpar;HostConfig&period;java&colon;663&rpar;<br &sol;>&NewLine;at org&period;apache&period;catalina&period;startup&period;HostConfig&dollar;DeployDescriptor&period;run&lpar;HostConfig&period;java&colon;1642&rpar;<br &sol;>&NewLine;at java&period;util&period;concurrent&period;Executors&dollar;RunnableAdapter&period;call&lpar;Executors&period;java&colon;471&rpar;<br &sol;>&NewLine;at java&period;util&period;concurrent&period;FutureTask&period;run&lpar;FutureTask&period;java&colon;262&rpar;<br &sol;>&NewLine;at java&period;util&period;concurrent&period;ThreadPoolExecutor&period;runWorker&lpar;ThreadPoolExecutor&period;java&colon;1145&rpar;<br &sol;>&NewLine;at java&period;util&period;concurrent&period;ThreadPoolExecutor&dollar;Worker&period;run&lpar;ThreadPoolExecutor&period;java&colon;615&rpar;<br &sol;>&NewLine;at java&period;lang&period;Thread&period;run&lpar;Thread&period;java&colon;744&rpar;<&sol;p>&NewLine;<p><b>Solution for java&period;lang&period;ClassNotFoundException&colon; org&period;springframework&period;web&period;servlet&period;DispatcherServlet<&sol;b><&sol;p>&NewLine;<p><b>Solution 1- <&sol;b>You did not include spring-beans and spring-context jars in your lib&period; If you are using maven &lpar;which will help a lot&rpar; those two lines will be enough<&sol;p>&NewLine;<pre class&equals;"highlight" name&equals;"code">&lt&semi;dependency&gt&semi;&NewLine; &lt&semi;groupId&gt&semi;org&period;springframework&lt&semi;&sol;groupId&gt&semi;&NewLine; &lt&semi;artifactId&gt&semi;spring-context&lt&semi;&sol;artifactId&gt&semi;&NewLine; &lt&semi;version&gt&semi;4&period;1&period;0&period;RELEASE&lt&semi;&sol;version&gt&semi;&NewLine;&lt&semi;&sol;dependency&gt&semi;&NewLine;&lt&semi;dependency&gt&semi;&NewLine; &lt&semi;groupId&gt&semi;org&period;springframework&lt&semi;&sol;groupId&gt&semi;&NewLine; &lt&semi;artifactId&gt&semi;spring-webmvc&lt&semi;&sol;artifactId&gt&semi;&NewLine; &lt&semi;version&gt&semi;4&period;1&period;0&period;RELEASE&lt&semi;&sol;version&gt&semi;&NewLine;&lt&semi;&sol;dependency&gt&semi;&NewLine;<&sol;pre>&NewLine;<p>&NewLine;<b>Solution 2- <&sol;b>The necessary jars are in your classpath but are not deployed on tomcat&period;<&sol;p>&NewLine;<ul style&equals;"text-align&colon; left&semi;">&NewLine;<li>spring-beans &&num;8211&semi; 4&period;1&period;0&period;RELEASE<&sol;li>&NewLine;<li>spring-webmvc &&num;8211&semi; 4&period;1&period;0&period;RELEASE<&sol;li>&NewLine;<li>spring &&num;8211&semi; 4&period;1&period;0&period;RELEASE<&sol;li>&NewLine;<&sol;ul>&NewLine;<div style&equals;"background-color&colon; &num;f2f9fc&semi; border&colon;1px solid &num;c9e6f2&semi;border-radius&colon;3px&semi;padding&colon;16px&semi;line-height&colon;1&period;45&semi;"><b>Spring MVC Related Posts<&sol;b><&sol;p>&NewLine;<ol style&equals;"text-align&colon; left&semi;">&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2012&sol;12&sol;spring-web-mvc-framework-chapter-38&period;html">Spring MVC Web Tutorial<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2017&sol;02&sol;spring-mvc-interview-questions-and-answers&period;html">Spring MVC Interview Questions<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2013&sol;07&sol;introduction-to-mvc&period;html">MVC Design Pattern<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2017&sol;02&sol;what-is-dispatcherservlet-in-spring-and-its-uses&period;html">Spring MVC DispatcherServlet <&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2017&sol;02&sol;difference-between-applicationcontext-webapplicationcontext-in-spring-mvc&period;html">Spring MVC WebApplicationContext and Root Application Context<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2012&sol;07&sol;stereotype-annotations-in-spring&period;html">Spring MVC &commat;Controller Annotation<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2016&sol;03&sol;requestmapping-annotation-in-spring-mvc&period;html">Spring MVC &commat;RequestMapping Annotation<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2017&sol;02&sol;requestparam-annotation-in-spring-mvc-with-example&period;html">Spring MVC &commat;RequestParam Annotation<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2014&sol;08&sol;modelattribute-in-spring-mvc&period;html">Spring MVC &commat;ModelAttribute Annotation<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2017&sol;02&sol;difference-between-applicationcontext-webapplicationcontext-in-spring-mvc&period;html">Spring MVC ContextLoaderListener<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2017&sol;02&sol;requestparam-vs-pathvariable-annotations-in-spring-mvc&period;html">Spring MVC &commat;RequestParam and &commat;PathVariable annotations<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2017&sol;02&sol;spring-mvc-internalresourceviewresolver-configuration-example&period;html">Spring MVC InternalResourceViewResolver <&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2012&sol;12&sol;spring-30-mvc-hello-world-example&period;html">Spring MVC Hello World Example<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2012&sol;12&sol;spring-exception-handling-example&period;html">Spring MVC Exception Handling Example<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2012&sol;12&sol;spring-mvc-with-hibernate-crud-example&period;html">Spring MVC with Hibernate CRUD Example<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2012&sol;12&sol;spring-3-mvc-tiles-plugin-with-example&period;html">Spring MVC Tiles Plugin with Example<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2012&sol;12&sol;spring-3-mvc-and-interceptor-with&period;html">Spring MVC Interceptor with example<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2013&sol;01&sol;integration-spring-mvc3-and-mongodb&period;html">Spring MVC with MongoDB CRUD Example<&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2012&sol;12&sol;spring-3-mvc-internationalization&period;html">Spring MVC Internationalization &&num;038&semi; Localization with Example<&sol;a><&sol;b><&sol;li>&NewLine;<&sol;ol>&NewLine;<&sol;div>&NewLine;<p>&NewLine;<&sol;div>&NewLine;<div class&equals;"wp-post-navigation"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <div class&equals;"wp-post-navigation-pre"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;struts-to-spring-mvc-migration&sol;">Previous<&sol;a> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <&sol;div> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <div class&equals;"wp-post-navigation-next"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;exception-handling-in-spring-mvc&sol;">Next<&sol;a> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <&sol;div> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;<&sol;div>&NewLine;<script type&equals;"text&sol;javascript">&NewLine;jQuery&lpar;document&rpar;&period;ready&lpar;function&lpar;&dollar;&rpar; &lbrace;&NewLine; &dollar;&period;post&lpar;'https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-admin&sol;admin-ajax&period;php'&comma; &lbrace;action&colon; 'mts&lowbar;view&lowbar;count'&comma; id&colon; '156'&rcub;&rpar;&semi;&NewLine;&rcub;&rpar;&semi;&NewLine;<&sol;script>

Dinesh Rajput

Dinesh Rajput is the chief editor of a website Dineshonjava, a technical blog dedicated to the Spring and Java technologies. It has a series of articles related to Java technologies. Dinesh has been a Spring enthusiast since 2008 and is a Pivotal Certified Spring Professional, an author of a book Spring 5 Design Pattern, and a blogger. He has more than 10 years of experience with different aspects of Spring and Java design and development. His core expertise lies in the latest version of Spring Framework, Spring Boot, Spring Security, creating REST APIs, Microservice Architecture, Reactive Pattern, Spring AOP, Design Patterns, Struts, Hibernate, Web Services, Spring Batch, Cassandra, MongoDB, and Web Application Design and Architecture. He is currently working as a technology manager at a leading product and web development company. He worked as a developer and tech lead at the Bennett, Coleman & Co. Ltd and was the first developer in his previous company, Paytm. Dinesh is passionate about the latest Java technologies and loves to write technical blogs related to it. He is a very active member of the Java and Spring community on different forums. When it comes to the Spring Framework and Java, Dinesh tops the list!

Share
Published by
Dinesh Rajput

Recent Posts

Strategy Design Patterns using Lambda

Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…

4 years ago

Decorator Pattern using Lambda

Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…

4 years ago

Delegating pattern using lambda

Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…

4 years ago

Spring Vs Django- Know The Difference Between The Two

Technology has emerged a lot in the last decade, and now we have artificial intelligence;…

4 years ago

TOP 20 MongoDB INTERVIEW QUESTIONS 2022

Managing a database is becoming increasingly complex now due to the vast amount of data…

4 years ago

Scheduler @Scheduled Annotation Spring Boot

Overview In this article, we will explore Spring Scheduler how we could use it by…

4 years ago