如果我使用注释,我是否需要在spring security xml中声明bean

时间:2011-03-25 19:18:16

标签: java annotations spring-security

这是我的春季安全档案

<!-- Declare an authentication-manager to use a custom userDetailsService -->
    <security:authentication-manager>
            <security:authentication-provider user-service-ref="customUserDetailsService">

            </security:authentication-provider>
    </security:authentication-manager>

    <!-- Use a Md5 encoder since the user's passwords are stored as Md5 in the database -->
    <bean class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" id="passwordEncoder"/>

    <!-- A custom service where Spring will retrieve users and their corresponding access levels  -->
    <bean id="customUserDetailsService" class="com.vaannila.service.CustomUserDetailsService" />

运行正常,我想问一下,如果我在CustomUserDetailsS​​ervice上使用@Service,那么我可以删除bean行形式的xml文件,spring security是否会从注释读取bean

1 个答案:

答案 0 :(得分:0)

是的,假设您没有将bean移动到其他ApplicationContext(这与您的<context:component-scan.../>声明的位置直接相关)。

相反,您可以@Autowired许多/大多数由特定id标识的Spr Sec bean。

相关问题