java - spring-security-web 加载上下文时出错

标签 java spring junit spring-security

我正在尝试使用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>

如果我不包括<sec:http>标签我没有收到错误。如果我只包含 <sec:http/>我确实收到了错误。

在我的 pom 中,我包含了:

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

最佳答案

像这样的 DTD 文件

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

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

关于java - spring-security-web 加载上下文时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14708230/

相关文章:

spring - 内部订阅 spring-websocket 消息

java - Eclipse JUnit 返回 ClassNotFoundException?

java - ParallelRunner : java. lang.IllegalArgumentException: 提供的 TestContext 的测试方法不能为 null

java - HttpUrlConnection 不起作用并显示 GET 和 POST 调用的不同状态代码

java - GWT:SelectionChangeEvent.Handler 未检测到 CellTable 上行的取消选择

java - Mockito 与 JavaMailSender

java - 在单个 map 中执行多个任务是好习惯吗

java - 为什么执行模拟方法时没有调用mockito?

java - 接口(interface)与 Final 类存储最终变量

java - CrudRepository OperationNotSupported