【发布时间】:2015-05-08 06:39:18
【问题描述】:
这是我的spring-security.xml 的标题:
<?xml version="1.0" encoding="UTF-8" ?>
<b:beans xmlns:b="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/security/oauth2
http://www.springframework.org/schema/security/spring-security-oauth2-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd ">
启动服务器时提示这个错误:
org.xml.sax.SAXParseException: schema_reference.4: 读取失败 架构文件 'http://www.springframework.org/schema/security/spring-security-oauth2-2.0.xsd', 因为 1) 找不到文件; 2) 文件不能 读; 3) 文档的根元素不是
。
我对此的看法:
链接有效,文档存在
如果我将此 xsd 放在本地类路径中,我可以阅读它,甚至可以重现此错误。所以这不是网络问题。
没错,文件以
<xs:schema>开头,而不是<xsd:schema>。但来源看起来是合法的。
为什么我会收到这个错误,我该如何摆脱它?
【问题讨论】:
-
请提供一个Minimal, Complete, and Verifiable Example (MCVE) 来说明问题。谢谢。
-
只需像 crunchify.com/… 或 github.com/spring-projects/spring-mvc-showcase/tree/master/src/… 这样的 spring-mvc 最小示例。然后,在 schemaLocation 中包含与版本一起列出的五个库。最后,添加 applicationContext.xml 中提供的几乎为空的 spring-security.xml。不要忘记关闭
标记。在 tomcat/jboss/jetty 服务器上启动这个应用程序。 -
有趣的是,我在本地下载了spring-security-oauth2-2.0.xsd,将所有出现的“xs:”前缀编辑为“xsd:”并将“xsi:schemaLocation”的第6行更改为“类路径:spring-security-oauth2-2.0.xsd”,它的工作原理。但是我不再使用官方的xsd。所以这不是一个可以接受的解决方案。
-
Spring XSD 通常也在 JAR 中,并且您 schemaLocation 中 URL 的映射通过 spring-security-oauth2 进一步映射到 spring-security-oauth2-xyzjar 的 XSD 文件-xyzjar\META-INF\spring.schemas。请检查您的 JAR,可能缺少 XSD 或映射有缺陷。
标签: spring spring-mvc spring-security xsd spring-security-oauth2