【问题标题】:spring-security-web error loading contextspring-security-web 错误加载上下文
【发布时间】:2013-01-20 10:06:21
【问题描述】:

我正在尝试使用Web Security Expressions,但是当我在单元测试中加载上下文时,我得到org.xml.sax.SAXParseException: The markup declarations contained or pointed to by the document type declaration must be well-formed

我的上下文文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:sec="http://www.springframework.org/schema/security"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">

 // various beans here

 <sec:http use-expressions="true">
   <sec:intercept-url pattern="/admin*"
      access="hasRole('admin') and hasIpAddress('192.168.1.0/24')"/>
  </sec:http>

</beans>

如果我不包含 &lt;sec:http&gt; 标签,我不会收到错误消息。如果我只包含&lt;sec:http/&gt;,我会收到错误消息。

在我的 pom 中,我包含了:

<dependancy>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
    <version>3.0.5.RELEASE</version>
</dependancy>

【问题讨论】:

  • 您对springframework.org/schema/security/spring-security-3.0.xsd URL(在您执行测试的环境中)有任何问题吗?
  • 我得到了 404 以及我使用的所有其他 xsd。我假设它是在运行时从 jar 中获取模式?不知道如何检查它是否可以与我使用的其他人相比。
  • 这个通常是通过网络加载的。我没有任何问题(可以在我的网络浏览器中查看)。
  • 这似乎是这个问题的表亲:stackoverflow.com/questions/2161050/…

标签: java spring junit spring-security


【解决方案1】:

像这样的DTD文件

http://www.springframework.org/schema/security/spring-security-3.0.xsd

必须在每个解析操作期间可用于 XML 解析器。让它们可用,问题就会消失。

【讨论】:

  • 因此,如果我们假设我的应用程序无法访问互联网,那么它一定是从某个地方获取架构(包括其他可以使用的架构)。我会假设它将从通过 maven 依赖项包含的 jar 中获取它。我在这里错了还是我没有正确的依赖关系?
  • 你是对的。 spring-security-config.jar 是正确的依赖项。
【解决方案2】:

原来 Spring Security 的架构在 spring-security-config jar 中。我需要那种依赖。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-11
    • 1970-01-01
    • 1970-01-01
    • 2012-03-22
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多