代码之家  ›  专栏  ›  技术社区  ›  Sean Patrick Floyd

访问方法返回类型的Spring aop切入点表达式

  •  8
  • Sean Patrick Floyd  · 技术社区  · 16 年前

    @Around(value = "execution(public *"
        + " com.mycompany.MyService+.*(..))"
        + " && args(request)"
        + " && returning( returnType)" // something like this would be nice
    
    , argNames = "request,returnType")
    public Object handleServiceCall(final ProceedingJoinPoint pjp,
        final Request request,
        final Class<? extends Response> returnType){ ... }
    
    2 回复  |  直到 16 年前
        1
  •  6
  •   Christian Semrau Louis Wasserman    16 年前

    的Javadoc JoinPoint 提到 getSignature() 方法,其返回类型 Signature 有一个子接口 MethodSignature getReturnType() ,这可能就是你要找的。

        2
  •  0
  •   chedine    16 年前

    您可以在around advice方法(在本例中为handleServiceCall())中进行检查

    Object actuals = pjp.proceed();
    if(actuals instanceof MyResponse){
    //TO:DO: Your code here
    }
    
    推荐文章