Recently in learning Springmvc, do HelloWorld instance when running the server has been reported: Java.lang.ClassNotFoundException: Org.springframework.web.servlet.DispatcherServlet error, I Baidu the class is located under the Spring-webmvc.jar package, after checking I'm sure I added the package into the project.
Baidu has a large number of solutions, and finally I tried the package needed to put the jar into the Lib package, and then refresh the project, you can successfully compile, solve the problem.
Thinking: Usually I am the build path jar package, after this operation, the jar package is under (), I looked under the Lib package is empty, but why I put the jar package in the Lib package can be?
Reason: Referenced librarier the following package jar package is to allow you to compile, if there is no spring and other jar package under the package, the project is written to the corresponding function, will not be prompted and complete, nature will not be compiled. While the jar file in the Lib package is loaded by a server such as Tomcat, the server loads the jar file under this package when running the Dynamic Web page project, so it will report java.lang.ClassNotFoundException: The root cause of the org.springframework.web.servlet.DispatcherServlet is that the corresponding jar file cannot be found in Lib and the file cannot be loaded.
Summary: When editing a project, Eclipse loads the jar file under referenced libraries to compile
When running the server, you need to load the jar file under the Lib package to run the project, that is, the path to the jar file that is loaded for the project is different when compiling and running.
Java.lang.ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet mistakes that make beginners headache