Spring MVC Schema给出了SAXParseException

时间:2015-01-21 04:52:22

标签: java xml spring spring-mvc

当我尝试在spring-mvc中添加dispatcher-servlet.xml架构时,出现以下错误。我从STS中给出的spring示例中复制了xml文件。我使用的是Spring 4.1.1。提起mvc架构而不是任何其他架构时,只会出现此问题:

org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 116; Error:  cos-all-limited.1.2:  The minOccurs attribute of a model group with "all" compositor that is part of a pair that is the content type of a complex type definition must have the value one.  The value "0" is incorrect.

我的档案是:

<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        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">
    <annotation-driven />
    <resources mapping="/resources/**" location="/resources/" />
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/jsp/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>       
    <context:component-scan base-package="com.mj.cchp" />    
</beans:beans>

2 个答案:

答案 0 :(得分:1)

没有名称空间作为&#34;资源&#34;。使用以下标记

 <mvc:resources mapping="/resources/**" location="/resources/"/>

要使这个工作正常,请添加mvc名称空间

<?xml version="1.0" encoding="UTF-8"?>
<beans 
 xmlns:mvc="http://www.springframework.org/schema/mvc"
 ....
 xsi:schemaLocation="
 http://www.springframework.org/schema/mvc
 http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
 ......

答案 1 :(得分:0)

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="com.mj.cchp" /> 
    <mvc:annotation-driven />
    <mvc:resources mapping="/resources/**" location="/resources/" />
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>          
</beans>

InternalResourceViewResolver用于解析受保护文件夹下的资源,例如WEB-INF

尝试以上。将beans设为default namespace。两者都应该有效,但这适用于Spring-4.1.1