具有多个注释的方法的AspectJ切入点 [英] AspectJ Pointcut on Methods with Multiple Annotations

查看:126
本文介绍了具有多个注释的方法的AspectJ切入点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用加载时编织,纯AspectJ。

Use load-time weaving, pure AspectJ.

我们有2个注释 @Time @Count ,以及一些带注释的方法。

We have 2 annotations @Time and @Count, and a few annotated methods.

@Time (name="myMethod1Time")
@Count (name="myMethod1Count")
public void myMethod1(){..};

@Time (name="myMethod2Time")
public void myMethod2(){..};

@Count (name="myMethod3Count")
public void myMethod3(){..};

现在我为 myMethod1 有多个注释:

// multiple annotations, not working
@Around("@annotation(time) && @annotation(count))
public Object myAspect(Time time, Count count) {..}

这不起作用。但是,捕获方法 myMethod2 可以使用单个注释正常工作:

This doesn't work. However, capture method myMethod2 works fine with a single annotation:

// single annotation, is working
@Around("@annotation(time))
public Object myAnotherAspect(Time time) {..}

我想只捕获同时包含 Time 的方法并且计数注释中存在注释,我想使用注释值。有人知道如何实现这个目标吗?

I want to capture only methods with both Time and Count annotations present in their signature, and I want to use the annotation value. Anyone know how to achieve this?

推荐答案

也许结合2个切入点如下:

Maybe combine 2 pointcuts like:

@Around("call(@Time * *(..)) && call(@Count * *(..))");

这篇关于具有多个注释的方法的AspectJ切入点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆