单例类获取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;
}