依赖Bug:java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet

I. Introduction

This bug tortured me all day! I created a springmvc project, but the request sent by the browser did not go through my Controller layer (404 error occurred!) Finally , an exception was found in the Tomcat Localhost Log :

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

The first reaction to this exception is to rely on a problem! But all our configurations are normal !

2. Reasons and solutions

Reason : When we created the SpringMVC project, if we used the Add Framework Support method, there would be no lib directory under WEB-INF, and our project was finally started through Tomcat! Although the jar package already exists, but a 404 burst indicates that there is no jar package in the project.

Solution :

  1. Open Projcet Structure, as shown in the figure:
    Insert picture description here

  2. We need to operate as shown below: Successfully deploy the jar package!
    Insert picture description here

  3. This is the discovery, just as we expected! There is a lib directory under the WEB-INF directory! Successful deployment of dependent jar!
    Insert picture description here

  4. Start the server, open the browser to send the request, and find that it is indeed successful! !

Three, summary

If you use the Spring framework in the future, you must remember: After importing the dependencies, go to Put Into Output Root in the Project Structure ! ! ! Remember! Otherwise, an exception will still occur!

Guess you like

Origin blog.csdn.net/weixin_46594796/article/details/112727945