简体   繁体   English

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

[英]Spring AOP - pointcut for every method with an annotation

I am trying to define a pointcut, that would catch every method that is annotated with (ie) @CatchThis . 我正在尝试定义一个切入点,它将捕获每个使用(即) @CatchThis注释的方法。 This is my own annotation. 这是我自己的注释。

Moreover, I'd like to have access to the first argument of the method, which will be of Long type. 此外,我想访问该方法的第一个参数,它将是Long类型。 There may be other arguments too, but I don't care about them. 可能还有其他争论,但我不关心它们。


EDIT 编辑

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 . 我不知道的是如何传递用@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();
    }
}

Something like this should do: 这样的事情应该做:

@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();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM