2017-02-25 227 views
0

我现在正在学习Spring MVC,并且我在互联网上运行演示作为指南,但是该错误是通配符匹配非常全面,但找不到元素'mvc:default-servlet-handler'语句)

[/WEB-INF/mvc-dispatcher-servlet.xml]无效;嵌套异常是org.xml.sax.SAXParseException; lineNumber:12; columnNumber:35; cvc-complex-type.2.4.c:通配符的匹配很全面,但无法找到元素'mvc:default-servlet-handler'的声明(通配符匹配非常全面,但找不到元素'mvc:default-servlet处理程序'声明)**。

这里是我的MVC-调度-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"> 
    <!--指明 controller 所在包,并扫描其中的注解--> 
    <context:component-scan base-package="com.snow.controller"/> 
    <!-- 静态资源(js、image等)的访问 --> 
    <mvc:default-servlet-handler/> 
    <!-- 开启注解 --> 
    <mvc:annotation-driven/> 

    <!--ViewResolver 视图解析器--> 
    <!--用于支持Servlet、JSP视图解析--> 
    <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
     <property name="prefix" value="/WEB-INF/pages/"/> 
     <property name="suffix" value=".jsp"/> 
    </bean> 

,我已经改变了pom.xml的春季版本4.3.5,从4.3.6,但它是没有用。 你会帮忙检查原因吗?

+0

你刚刚删除XML注释? –

+0

我刚才尝试,没用。 – Luca

+0

那么,删除它们时的错误应该不同,所以请更新问题。 –

回答

0

同样的问题,我解决它。 https://github.com/gaussic/SpringMVCDemo/blob/master/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml

将代码从github url new中取代。

<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" 
    xmlns:jpa="http://www.springframework.org/schema/data/jpa" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    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 
    http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd 
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> 
相关问题