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

发布于 2024-10-26 20:43:23 字数 948 浏览 1 评论 0原文

这是我的 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 那么我可以删除 xml 文件中的 bean 行吗? spring security 将从注释中读取 bean 或不是

this is my spring security file

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

This is running fine , i want to ask that if i use @Service on CustomUserDetailsService then can i delete the bean line form xml file and spring security will read the bean from annotation or not

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枯叶蝶 2024-11-02 20:43:23

是的,假设您没有将 bean 移动到不同的 ApplicationContext(这与您的 声明的位置直接相关)。

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

Yes, assuming you don't move the bean to a different ApplicationContext (this is directly related to the location of your <context:component-scan.../> declaration).

Conversely, you can @Autowired many/most of the Spr Sec beans which are identified by a specific id.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文