2013-02-05 49 views
0

我試圖用Web Security Expressions然而,當我在單元測試負載的情況下,我得到org.xml.sax.SAXParseException: The markup declarations contained or pointed to by the document type declaration must be well-formed彈簧安全的web錯誤加載上下文

我的背景文件看起來像這樣:

<?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> 
+0

您對http://www.springframework.org/schema/security/spring-security-3.0.xsd URL(在執行測試的環境中)有任何問題嗎? –

+0

我得到了404以及我使用的所有其他xsds。我假設它在運行時從jar中獲取模式?不知道如何檢查是否可以找到它與我使用的其他人。 –

+0

這個通常通過網絡加載。我沒有任何問題(可以在我的網頁瀏覽器中查看)。 –

回答

1

DTD文件,像這樣的

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

每個解析動作時必須可用XML解析器。使它們可用並且問題將消失。

+0

因此,如果我們假設我的應用程序無法訪問互聯網,它必須從某個地方獲取架構(包括可以使用的其他架構)。我會假設它會通過maven依賴包含在jar中。我在這裏錯了還是沒有合適的依賴? –

+0

你說得對。 spring-security-config.jar是正確的依賴項。 –

0

原來彈簧安全的模式在spring-security-config罐子裏。我需要這種依賴性。