2015-09-13 72 views
2

我想使用Spring Security所以可以這樣來配置無法讀取模式文檔「http://www.springframework.org/schema/security/spring-security-4.0.xsd」

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/security" 
xmlns:beans="http://www.springframework.org/schema/beans" 
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.xsd 
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd"> 

    <http> 
     <intercept-url pattern="/add-job**" access="hasRole('USER')" /> 
     <form-login /> 
     <logout /> 
    </http> 

    <authentication-manager> 
     <authentication-provider> 
      <user-service> 
      <user name="admin" password="admin" authorities="ROLE_USER, ROLE_ADMIN" /> 
      </user-service> 
     </authentication-provider> 
    </authentication-manager> 

</beans:beans> 

,但我「m到處錯誤,

在這條線找到多個註釋: - schema_reference.4:無法讀取模式文檔」 http://www.springframework.org/schema/ 安全/彈簧安全4.0.xsd」,因爲:1)找不到文件; 2)文件無法閱讀; 3) 該文件的根元素不是。 - cvc-complex-type.2.4.c:匹配通配符是嚴格的,但是對於元素 'http'沒有聲明。

和我的安全pom.xml的是

<!-- Security --> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-web</artifactId> 
      <version>4.0.2.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-config</artifactId> 
      <version>4.0.2.RELEASE</version> 
     </dependency> 

我不能找到辦法來解決這個問題。

回答

3

感謝回答傢伙,但最後我發現一個解決方案在Migrating from Spring Security 3.x to 4.x (XML Configuration),發現以下依賴

<dependency> 
    <groupId>org.springframework.security</groupId> 
    <artifactId>spring-security-core</artifactId> 
    <version>4.0.0.RELEASE</version> 
</dependency> 

這連同在問題中提到的一面,這種方法解決我的問題。

1

Spring建議使用http://www.springframework.org/schema/security/spring-security.xsd來代替指定版本號,就像您使用spring-beans一樣。

這樣,我有一個項目具有相同的彈簧安全依賴關係,但是4.0.2.RELEASE我有4.0.1.RELEASE,它沒有問題。

所以,你必須嘗試的模式配置如下:

xsi:schemaLocation=" 
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd 
    http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans.xsd" 

如果它不工作,那麼你可能有一個傳遞依賴的問題,您只是加載兩個或兩個以上不同的彈簧安全的版本。在這種情況下,請嘗試使用mvn dependency:tree來查看是否有多個彈簧安全性依賴於configuration工件,並排除不需要的工件。

+0

謝謝,但我的回答解決了我的問題。 –

+0

這很奇怪,正如我告訴你的,我和這兩個依賴關係都有非常相似的項目。我只運行依賴關係樹,並且我看到'spring-security-core'包含'spring-security-web'和'4.0.0.RELEASE'。它以這種方式爲我工作。 – malaguna

相關問題