Java.lang.ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet mistakes that make beginners headache

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.