0

注釈付きメソッドへのポイントカットでアスペクトを作成しました。私が得るのJoinPointは、メソッドの実装ではなく、インターフェイスからのメソッド宣言です。したがって、注釈付きのメソッドパラメーターを取得したい場合は、実装ではなくインターフェースに注釈を追加する必要があります。

@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メソッドの実装に追加されている場合、注釈はありません。正しいポイントカットは何でしょうか?

4

1 に答える 1

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

出典:Spring AOP:アドバイスされたメソッドのアノテーションを取得する方法

于 2012-09-28T12:52:39.683 に答える