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 :
-
Open Projcet Structure, as shown in the figure:
-
We need to operate as shown below: Successfully deploy the jar package!
-
This is the discovery, just as we expected! There is a lib directory under the WEB-INF directory! Successful deployment of dependent jar!
-
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!