2017-01-01 171 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