Spring Security - 无法找到Spring NamespaceHandler - security

时间:2017-01-01 16:45:33

标签: java spring spring-security

我有异常: org.springframework.beans.factory.parsing.BeanDefinitionParsingException:配置问题:无法找到XML架构命名空间的Spring NamespaceHandler [http://www.springframework.org/schema/security] 违规资源:ServletContext资源[/WB-INF/spring/security.xml]

谷歌几分钟,说我,我需要添加依赖 - spring-security-config。我有这个,最新版本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>

1 个答案:

答案 0 :(得分: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 Tool Suite或Eclipse,请务必右键单击您的项目,然后选择Maven -> Update Project并填写clean install