0
votes

I created an Aspect with a pointcut to annotated method. What I get as JoinPoint is method declaration from Interface not method implementation. So when I want to get annotated method parameters I have to add annotation in interface not in implementation.

@AfterReturning(value = "@annotation(pl.styall.scylla.security.authorization.acl.AclSecure) && @annotation(aclSecure)", argNames = "jp,aclSecure,retVal", returning = "retVal")
public void addObjectAndEntry(JoinPoint jp, AclSecure aclSecure,
        Object retVal) {
    System.out.println(jp.toLongString());
    MethodSignature signature = (MethodSignature) jp.getSignature();
    Method method = signature.getMethod();
    Annotation[][] methodAnnotations = method.getParameterAnnotations();

methodAnnotations has no annotations if they are add in method implementation. What would be the correct pointcut?

1

1 Answers

2
votes
final String methodName = pjp.getSignature().getName();
final MethodSignature methodSignature = (MethodSignature)pjp.getSignature();
Method method = methodSignature.getMethod();
if (method.getDeclaringClass().isInterface()) {
    method = pjp.getTarget().getClass().getDeclaredMethod(methodName, method.getParameterTypes());    
}

Source: Spring AOP: how to get the annotations of the adviced method