2017-02-25 225 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"> 
相關問題