2017-01-01 230 views
0

我有例外:org.springframework.beans.factory.parsing.BeanDefinitionParsingException:配置問題:找不到春天NamespaceHandler XML模式命名空間[http://www.springframework.org/schema/security] 犯規資源:ServletContext的資源[/WEB-INF/spring/security.xml]春季安全 - 無法找到春天NamespaceHandler - 安全

在谷歌幾分鐘,說我,我需要添加依賴性 - 彈簧安全配置。我有這個,最新版本4.2.1,但有例外。

的security.xml

<?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-4.1.xsd 
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd"> 

<beans:bean name="standartEncrypt" 
      class="org.springframework.security.crypto.password.StandardPasswordEncoder" > 
    <beans:constructor-arg name="secret" value="3u6gui" /> 
</beans:bean> 

<http auto-config="true" > 
    <intercept-url pattern="/notes/**" access="authenticated" /> 
    <intercept-url pattern="/register" requires-channel="https" /> 
    <intercept-url pattern="/" access="permitAll" /> 
    <intercept-url pattern="/accessDenied" access="permitAll" /> 
    <intercept-url pattern="/duplicate" access="permitAll" /> 
    <intercept-url pattern="/notExists" access="permitAll" /> 

    <access-denied-handler error-page="/accessDenied" /> 

    <logout 
      logout-success-url="/index" 
      logout-url="/notes/{username}/exit" 
    /> 
    <form-login 
      authentication-failure-url="/accessDenied" 
      login-page="/register" 
      login-processing-url="/register" 
      password-parameter="password" 
      username-parameter="username" 
    /> 
    <remember-me data-source-ref="dataSource" /> 

    <session-management session-fixation-protection="newSession"> 
     <concurrency-control max-sessions="1" error-if-maximum-exceeded="true" /> 
    </session-management> 
</http> 

<authentication-manager > 
    <authentication-provider> 
     <password-encoder ref="standartEncrypt" /> 
     <jdbc-user-service data-source-ref="dataSource" users-by-username-query="SELECT username, password FROM Users WHERE username = ?"/> 
    </authentication-provider> 
</authentication-manager> 

<global-method-security jsr250-annotations="enabled" secured-annotations="enabled" /> 

行家

<dependency> 
    <groupId>org.springframework.security</groupId> 
    <artifactId>spring-security-config</artifactId> 
    <version>4.2.1.RELEASE</version> 
</dependency> 

回答

0

這可能是一個未解決的依賴。沒有看到你的Maven POM或項目配置,最低限度爲Spring Security是:

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

如果您在使用Spring工具套件或Eclipse中,一定要右鍵單擊您的項目,然後選擇Maven -> Update Project並做了充分的clean install