猿问

跟老师的一样,找不到DispatcherServlet,一直报404,为什么?

我用的tomcat,服务器一启动就会报:

严重: Servlet [mvc-dispatcher] in web application [/spring-mvc-study] 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$StartChild.call(ContainerBase.java:1407)

at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)

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)


九月 25, 2016 12:45:33 下午 org.apache.coyote.AbstractProtocol start


为什么找不到DispatcherServlet啊??


我web.xml文件如下:

<!DOCTYPE web-app PUBLIC

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

 "http://java.sun.com/dtd/web-app_2_3.dtd" >


<web-app>

  <display-name>Archetype Created Web Application</display-name>

  <!-- DispatcherServlet, Spring MVC的核心 -->

  <servlet>

<servlet-name>mvc-dispatcher</servlet-name>

<servlet-class> org.springframework.web.servlet.DispatcherServlet</servlet-class>

<!-- DispatcherServlet对应的上下文配置, 默认为/WEB-INF/$servlet-name$-servlet.xml

-->

<init-param>

          <param-name>contextConfigLocation</param-name>

          <param-value>/WEB-INF/configs/spring/mvc-dispatcher-servlet.xml</param-value>

        </init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>mvc-dispatcher</servlet-name>

   <!-- mvc-dispatcher拦截所有的请求-->

<url-pattern>/</url-pattern>

</servlet-mapping>

  

  

  

</web-app>


我mvc-dispatcher-servlet.xml内容如下:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="

        http://www.springframework.org/schema/beans

        http://www.springframework.org/schema/beans/spring-beans.xsd

        http://www.springframework.org/schema/context 

        http://www.springframework.org/schema/context/spring-context.xsd

        http://www.springframework.org/schema/mvc

        http://www.springframework.org/schema/mvc/spring-mvc.xsd ">


<!-- 本配置文件是工名为mvc-dispatcher的DispatcherServlet使用, 提供其相关的Spring MVC配置 -->


<!-- 启用Spring基于annotation的DI, 使用户可以在Spring MVC中使用Spring的强大功能。 

激活 @Required @Autowired,JSR 250's @PostConstruct, @PreDestroy and @Resource 等标注 -->

<context:annotation-config />


<!-- DispatcherServlet上下文, 只管理@Controller类型的bean, 忽略其他型的bean, 如@Service -->

<context:component-scan base-package="com.imooc.mvcdemo">

<context:include-filter type="annotation"

expression="org.springframework.stereotype.Controller" />

</context:component-scan>


<!-- HandlerMapping, 无需配置, Spring MVC可以默认启动。 DefaultAnnotationHandlerMapping 

annotation-driven HandlerMapping -->


<!-- 扩充了注解驱动,可以将请求参数绑定到控制器参数 -->

<mvc:annotation-driven />


<bean

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />

<property name="prefix" value="/WEB-INF/jsps/" />

<property name="suffix" value=".jsp" />

</bean>


</beans>


访问http://localhost:8080/spring-mvc-study这个正常显示


访问http://localhost:8080/spring-mvc-study/hello/mvc 就报404错误

项目目录:

我真的不认为哪里还有问题了,求大神指点



一升米
浏览 6749回答 4
4回答

慕粉4075985

每导包?

cary_candy

照这你的代码敲了一遍 没问题啊
随时随地看视频慕课网APP

相关分类

Java
我要回答