Spring AOP - pointcut pour chaque méthode avec une annotation
-
26-10-2019 - |
Question
Je suis en train de définir un point de coupure, qui attirerait toutes les méthodes qui annotées avec (par exemple) @CatchThis
. Ceci est ma propre annotation.
De plus, je voudrais avoir accès au premier argument de la méthode, qui sera de type Long
. Il peut y avoir d'autres arguments aussi, mais je ne se soucient pas eux.
EDIT
est ce que j'ai en ce moment. Ce que je ne sais pas comment passer le premier paramètre de la méthode annotée avec @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();
}
}
La solution
Quelque chose comme cela devrait faire:
@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();
}
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow