【问题标题】:XSD error when trying to upgrade Spring to 3.1 or above尝试将 Spring 升级到 3.1 或更高版本时出现 XSD 错误
【发布时间】: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.xmlmvc-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


【解决方案1】:

我设法通过添加 xerces:xercesImpl:2.12.1xml-apis:xml-apis:1.4.01(不是 2.0.2,由于某种原因似乎只是指向旧的 beta 版本)作为依赖项来使其工作。这让我升级到 spring 版本 3.2.18。尝试升级到 4.0 或更高版本时遇到了其他不相关的问题,正如更改主要版本时所预料的那样。

【讨论】:

  • 如果你有一些最近的 JDK,我会放弃这些依赖项,因为 xml-api 等是 JDK 的一部分。
  • 我使用的是 JDK 8,但添加这些依赖项是它工作的原因,所以 idk。
猜你喜欢
  • 1970-01-01
  • 2023-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多