簡體   English   中英

如果我使用注釋,是否需要在Spring Security xml中聲明bean

[英]Do i need to declare bean in spring security xml if i use annotation

這是我的春季安全文件

<!-- 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" />

這是運行良好,我想問問,如果我使用@Service上CustomUserDetailsS​​ervice然后我可以刪除豆線形式的XML文件和春季安全將注釋讀取Bean或不

是的,假設您沒有將Bean移動到其他ApplicationContext(這與<context:component-scan.../>聲明的位置直接相關)。

相反,您可以@Autowired通過特定id標識的許多/大多數Spr Sec bean。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM