[英]Failed to read schema document 'http://www.springframework.org/schema/security/spring-security-3.2.xsd'
[英]Failed to read schema document 'http://www.springframework.org/schema/security/spring-security-4.0.xsd'
我想使用如此配置的Spring安全性
<?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>
但我得到了錯誤
在此行找到多個批注:-schema_reference.4:無法讀取架構文檔' http://www.springframework.org/schema/ security / spring-security-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>
我找不到解決此問題的方法。
感謝Answering Guys,但最終我在從Spring Security 3.x遷移到4.x(XML配置)時找到了一個解決方案,並找到了以下依賴項
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
這與Question中提到的一樣,這種方法解決了我的問題。
Spring建議您像使用spring-beans
一樣使用此http://www.springframework.org/schema/security/spring-security.xsd
而不是指定版本號。
這樣,我有一個具有相同的Spring Security依賴項的項目,但是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"
如果它不起作用,那么您可能會遇到傳遞依賴項問題,您只是在加載兩個或更多不同的spring安全版本。 在這種情況下,請嘗試使用mvn dependency:tree
來查看您在configuration
工件上是否具有多個spring-security依賴,並排除不必要的依賴。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.