【问题标题】:Do i need to declare bean in spring security xml if i use annotation如果我使用注释,我是否需要在 Spring Security xml 中声明 bean
【发布时间】:2011-03-26 06:26:37
【问题描述】:

这是我的 spring 安全文件

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

【问题讨论】:

    标签: java annotations spring-security


    【解决方案1】:

    是的,假设您不将 bean 移动到不同的 ApplicationContext(这与您的 &lt;context:component-scan.../&gt; 声明的位置直接相关)。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-26
      • 1970-01-01
      • 2020-03-09
      • 2021-12-04
      • 2015-02-06
      • 2010-11-23
      • 2018-01-26
      • 2021-11-19
      相关资源
      最近更新 更多