加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java – 服务的任何公共方法的AOP切入点表达式

发布时间:2020-12-15 01:45:35 所属栏目:大数据 来源:网络整理
导读:什么是最简单的切入点表达式,它将拦截使用@Service注释的所有bean的所有公共方法?例如,我希望它会影响这个bean的两个公共方法: @Servicepublic MyServiceImpl implements MyService { public String doThis() {...} public int doThat() {...} protected i

什么是最简单的切入点表达式,它将拦截使用@Service注释的所有bean的所有公共方法?例如,我希望它会影响这个bean的两个公共方法:

@Service
public MyServiceImpl implements MyService {
    public String doThis() {...}
    public int doThat() {...}
    protected int doThatHelper() {...} // not wrapped
}
最佳答案
这documentation应该非常有帮助.

我会创建两个单独的点切割,一个用于所有公共方法,一个用于所有使用@Service注释的类,然后创建第三个,它结合了另外两个的切入点表达式.

查看(7.2.3.1支持的切入点指示符)以供使用的指示符.我认为你是在寻找公共方法的“执行”指示符之后,以及用于查找注释的“注释”指示符.

然后看一下(7.2.3.2组合切入点表达式)来组合它们.

我在下面提供了一些代码(我没有测试过).它主要来自文档.

@Pointcut("execution(public * *(..))") //this should work for the public pointcut
private void anyPublicOperation() {}

//@Pointcut("@annotation(Service)") this might still work,but try 'within' instead
@Pointcut("@within(Service)") //this should work for the annotation service pointcut
private void inTrading() {}

@Pointcut("anyPublicOperation() && inTrading()")
private void tradingOperation() {}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读