java - Spring MVC 模式给出 SAXParseException

标签 java xml spring spring-mvc

当我尝试在 dispatcher-servlet.xml 中添加 spring-mvc 架构时,出现以下错误。我已经从 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>

最佳答案

没有命名空间作为“资源”。使用以下标签,

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

关于java - Spring MVC 模式给出 SAXParseException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28059844/

相关文章:

xml - 如何使用 XSLT 在 XML 中设置属性?

java - Hibernate 中如何获取共享锁和独占锁

spring - 逃离| SpEL 中的(管道)

java - PMD:避免使用分支语句作为循环中的最后一个语句

java - 如何在接口(interface)处编写通用方法参数

java - 在 Android 中使用 MapController 的 setCenter 方法时出现空指针异常

php - 在 Yii 2 Response 中为 XML 标签添加属性

php - 使用 DomDocument 将实体添加到 DOCTYPE

java - 如何在构造函数上使用 @Autowired DI Autowiring 未定义 bean 的属性?

java - 给嵌套 map java赋值