在写springMVC时,导入所有需要的包后,运行程序,控制台报以下错误:
严重: Servlet [springDispatcherServlet] in web application [/SpringMVC-1] threw load() exception java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:518) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:499) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1027) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5038) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5348) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717) at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:587) at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1798) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
随便在一个java文件中都无法import org.springframework.web.servlet.DispatcherServlet,这个类主要是在spring-webmvc jar包下,所有导入的jar包如下:
都已经导入,没有问题。但是实际上还要把依赖都加进classpath下。步骤:
项目右击-->properties-->Deployment Assembly-->add-->Java Build Path Entries-->导入所有依赖的Jar包,重新start tomcat即可。
时间: 2024-09-28 05:20:51