如果我使用注释,我需要在 spring security xml 中声明 bean
这是我的 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" />
运行良好,我想问一下,如果我在 CustomUserDetailsService 上使用 @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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,假设您没有将 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 specificid
.