spring获取当前动态代理对象

由于spring中的aop拦截的是代理对象

当拦截的目标方法被本类的另一个方法调用时,会出现拦截失效

最佳实践:

例如拦截RegulationService的update(regulation)方法,当RegulationService的add方法(当前类的非update方法)调用update方法时,为了依然能拦截到

update方法

可使用如下方式获取当前代理对象

public int add(...){

Regulation result = ((RegulationService)(AopContext.currentProxy())).update(regulation);// 获取当前代理

......

}

posted @ 2019-10-18 20:09  qing222  阅读(5444)  评论(0编辑  收藏  举报