2015-01-21 54 views
1

当我尝试在dispatcher-servlet.xml中添加spring-mvc模式时,出现以下错误。我从STS中给出的spring示例中复制了xml文件。我正在使用Spring 4.1.1。只有起诉mvc架构时,而不是其他任何会发生此问题:给出SAXParseException的Spring 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> 
+0

您提供的错误和架构似乎不相关。你确定? – Keerthivasan 2015-01-21 04:55:10

+0

@Keerthivasan是的。只有当我包含mvc模式时才会出现此错误,否则将发生此错误。 – khateeb 2015-01-21 04:58:52

+0

导入的XSD模式文件可能存在问题。版本冲突。我认为您需要在'schemaLocation'属性中提供适当版本的XSD的URL。请查看 – Keerthivasan 2015-01-21 05:01:28

回答

1

没有命名空间的“资源”。使用下面的标签,

<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 
...... 
+0

是的,有一个'资源'元素。在这里搜索元素:http://www.springframework.org/schema/mvc/spring-mvc.xsd。 放置版本号给出了相同的错误。 – khateeb 2015-01-21 05:11:17

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

+0

不,我曾试过。它不起作用。 – khateeb 2015-01-21 11:01:29

+0

这是没有版本的更好的架构。 Spring指向最新版本的xsds。 如果不在罐子或罐子里的xsd不在班级路径中,可能会发生这种情况。 所以清理你的项目并运行最新的罐子。 或者有时春天可能会使用另一个版本而不是4.1(谁知道)。 获取最新的罐子,或者如果这是一个maven项目,请移除弹簧罐并重新更新。 – sura2k 2015-01-21 11:20:47