Spring AOP - 带有注释的每个方法的切入点

Spring AOP  - 带有注释的每个方法的切入点

问题描述:

我正在尝试定义一个切入点,它将捕获每个注释的方法(即) @CatchThis 。这是我自己的注释。

I am trying to define a pointcut, that would catch every method that is annotated with (i.e.) @CatchThis. This is my own annotation.

此外,我想访问该方法的第一个参数,该参数将是 Long 类型。可能还有其他论点,但我不关心它们。

Moreover, I'd like to have access to the first argument of the method, which will be of Long type. There may be other arguments too, but I don't care about them.

EDIT

这就是我现在所拥有的。我不知道的是如何传递用 @CatchThis 注释的方法的第一个参数。

This is what I have right now. What I don't know is how to pass the first parameter of the method annotated with @CatchThis.

@Aspect 
public class MyAspect {
    @Pointcut(value = "execution(public * *(..))")
    public void anyPublicMethod() {
    }

    @Around("anyPublicMethod() && @annotation(catchThis)")
    public Object logAction(ProceedingJoinPoint pjp, CatchThis catchThis) throws Throwable {
        return pjp.proceed();
    }
}


东西这样应该这样做:

@Aspect
public class MyAspect{

    @Pointcut(value="execution(public * *(..))")
    public void anyPublicMethod() {
    }

    @Around("anyPublicMethod() && @annotation(catchThis) && args(.., Long ,..)")
    public Object logAction(
        ProceedingJoinPoint pjp, CatchThis catchThis, Long long)
        throws Throwable {

        return pjp.proceed();
    }
}