单例java类获取spring的bean方法

本文介绍了一个使用Spring框架实现的数据权限类,通过单例模式管理并获取应用中所需的多个Bean实例,如员工权限管理和部门权限管理等服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

单例类获取spring的bean

/**
 * 
 * @ClassName: AuthorityUtil 
 * @Description:  (获取数据权限类) 
 * @author zuoqiang
 * @date 2017年2月6日 上午10:18:51 
 *
 */
@Component
public class AuthorityUtil {

protected Logger logger = Logger.getLogger(this.getClass());

private static AuthorityUtil authorityUtil;

//需要调用的bean
@Resource(name="employee_authorityService")
private Employee_AuthorityManager employee_authorityService;

//需要调用的bean
@Resource(name="dept_authorityService")
private Dept_AuthorityManager dept_authorityService;

//此注解的作用是在bean初始化之前,把需要的bean进行赋值
@PostConstruct
public void init() {
authorityUtil = this;
authorityUtil.employee_authorityService = employee_authorityService;
authorityUtil.dept_authorityService = dept_authorityService;
}

public static AuthorityUtil getInstance(){

if (authorityUtil == null)
{
authorityUtil = new AuthorityUtil();


return authorityUtil;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值