spring security 构造函数初始化bean思路

采用有参数的构造方法来解决注入你要的属性例如:
public MyInvocationSecurityMetadataSource(RoleService roleService) {
  this.roleService = roleService;
  loadResourceDefine();
}

RoleService 是可以获得资源列表的组件.
在xml配置文件中采用构造函数注入的方式把RoleService 注入到MyInvocationSecurityMetadataSource中.例如
<beans:bean id="securityMetadataSource"
class="com.shoesishow.security.MyInvocationSecurityMetadataSource">
<beans:constructor-arg><beans:ref bean="roleService"/></beans:constructor-arg>
</beans:bean>

posted @ 2014-07-31 13:49  全新时代-小小程序员大梦想  阅读(396)  评论(3编辑  收藏  举报