Feder AOP - Pointcut für jede Methode mit Annotation
-
26-10-2019 - |
Frage
Ich versuche, eine Pointcut zu definieren, die jede Methode fangen würde, mit der mit (dh) kommentiert wird, mit Annotierungen versehen. @CatchThis
. Dies ist meine eigene Annotation.
Darüber hinaus möchte ich Zugriff auf das erste Argument der Methode haben, das von aussehen wird Long
Typ. Es mag auch andere Argumente geben, aber ich kümmere mich nicht um sie.
BEARBEITEN
Das habe ich gerade. Ich weiß nicht @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();
}
}
Lösung
So etwas sollte tun:
@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();
}
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow