0

这是一个非常简单的问题,我正在学习一个教程,并且已经到了将密码编码器添加到我的 spring 安全性的地步,我有以下 XML ......

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

    <http pattern="/static/**" security="none" />
    <http use-expressions="true">
        <intercept-url pattern="/login" access="permitAll" />
        <intercept-url pattern="/*" access="isAuthenticated()" />
        <!-- <intercept-url pattern="/secure/extreme/**" access="hasRole('supervisor')" 
            /> -->
        <!-- <intercept-url pattern="/listAccounts.html" access="isAuthenticated()" 
            /> -->
        <!-- <intercept-url pattern="/post.html" access="hasAnyRole('supervisor','teller')" 
            /> -->
<!--        <intercept-url pattern="/*" access="denyAll" /> -->
        <form-login />
        <logout invalidate-session="true" logout-success-url="/"
            logout-url="/logout" />
    </http>

    <authentication-manager>
        <authentication-provider user-service-ref="customUserDetailsService">
          <password-encoder ref="passwordEncoder"/>
        </authentication-provider>
</authentication-manager>

<bean class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" id="passwordEncoder"/>

</beans:beans> 

问题是<bean class="org.spr..底部的行错误地说安全命名空间不允许

我确实理解这一点,但是有没有一种方法可以使用该参考而无需添加<security:到其他所有内容中?

4

2 回答 2

3

在您的 XML 声明中,您声明“security:”是默认命名空间:

xmlns="http://www.springframework.org/schema/security"

你必须在安全命名空间中找不到的所有元素加上它们的前缀......在这种情况下,bean 在 beans 命名空间中......所以你需要说,beans:bean

于 2012-07-06T17:23:28.053 回答
2

本声明:

<bean class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" id="passwordEncoder"/>

应该:

<beans:bean class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" id="passwordEncoder"/>
于 2012-07-06T17:25:45.513 回答