【发布时间】:2022-01-03 02:10:10
【问题描述】:
从 Spring 3.0.4 开始,当我尝试升级它时,我收到以下错误。这发生在下一个次要版本 (3.1.0) 和绝对最新版本 (5.3.13) 中。在我当前的次要版本 3.0.7 的最新补丁中不会发生这种情况。
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 23 in XML document from URL [file:src/main/webapp/WEB-INF/mvc-dispatcher-servlet-test.xml] is invalid; nested exception is org.xml.sax.SAXParseException; systemId: http://www.springframework.org/schema/mvc/spring-mvc.xsd; lineNumber: 23; columnNumber: 20; cos-all-limited.1.2: An ''all'' model group must appear in a particle with '{'min occurs'}'='{'max occurs'}'=1, and that particle must be part of a pair which constitutes the '{'content type'}' of a complex type definition.
经过调查,问题似乎来自spring-webmvc-3.1.0.RELEASE.jar/org/springframework/web/servlet/config/spring-mvc-3.1.xsd(或在5.3.13,spring-webmvc-5.3.13.jar/org/springframework/web/servlet/config/spring-mvc.xsd)。
与同一文件的 3.0 版本 (https://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd) 相比,3.1 (https://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd) 似乎在错误中指定的行周围添加了一个新标签 <xsd:all minOccurs="0">。手动编辑 jar 以将 minOccurs="0" 更改为 minOccurs="1" 使问题消失。但显然手动编辑 maven 依赖项并不是真正的修复。
我想我需要对我的mvc-dispatcher-servlet.xml 和mvc-dispatcher-servlet-test.xml 文件进行一些更改,但我不知道会发生什么更改。这些文件中唯一与 mvc 相关的标签是 <mvc:resources .../> 和 <mvc:annotation-driven />。
我需要改变什么来解决这个问题?
【问题讨论】:
-
请添加导致错误的xml。
-
错误来自
spring-mvc.xsd。就像我说的更改该文件可以修复错误,但它是依赖项的一部分,因此更改它实际上不是解决方案。 -
这不是我的问题,添加您自己的 XML 而不是 spring 的。成千上万(而不是数百万人)的人已经使用这些 XSD 没有错误,所以我非常怀疑这些 XSD 是否存在错误。错误出在您自己的 XML 或您的 XML 解析器(可能太旧)中。
-
好的,看起来是解析器。我没有一个专门定义的在 3.0 中工作的,但我猜想成为 3.1 及更高版本的问题。我添加了几个依赖项(请参阅我的答案)并让它工作。
标签: java spring maven spring-mvc xsd