【问题标题】:Pointcut to method implementation方法实现的切入点
【发布时间】:2012-09-28 12:24:38
【问题描述】:

我创建了一个带有注释方法的切入点的 Aspect。我得到的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 如果添加到方法实现中,则没有注释。正确的切入点是什么?

【问题讨论】:

    标签: java spring aspectj spring-aop


    【解决方案1】:
    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: how to get the annotations of the adviced method

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-31
      • 2014-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多