aop切面日志.多个表达式

代码如下:

@Pointcut("execution(* com..*.service.impl.*AdapterImpl.*(..)) || " +
        "execution(* com..*.mgr.impl.MerchantInfoManagerImpl.*(..))")
public void pointCut() {

}

@Before("pointCut()")
public void beforeExec(JoinPoint joinPoint) {
  log.info("{}.{} params:{}", joinPoint.getTarget().getClass().getName(), joinPoint.getSignature().getName(), JSON
      .toJSONString(joinPoint.getArgs()));
}

@AfterReturning(pointcut = "pointCut()", returning = "result")
public void afterExec(JoinPoint joinPoint, Object result) {
  Response Response = new Response();
  if (result instanceof Response) {
    BeanUtils.copyProperties(result, Response);
    if (!"000000".equals(Response.getReturnCode()) && !"0".equals(Response.getReturnCode())) {
      log.error("{}.{} response:{}", joinPoint.getTarget().getClass().getName(),
          joinPoint.getSignature().getName(), JSON.toJSONString(Response));
    } else {
      log.info("{}.{} response:{}", joinPoint.getTarget().getClass().getName(),
          joinPoint.getSignature().getName(), JSON.toJSONString(Response));
    }
  // 非Response类型dubbo交互非法
  } else {
    log.warn("{}.{} Error type; result is Should be Response", joinPoint.getTarget().getClass().getName(),
        joinPoint.getSignature().getName());
  }


}

@AfterThrowing(pointcut = "pointCut()", throwing = "e")
public void afterThrowExec(Throwable e) {
  log.error(e.getMessage(), e);
}

你可能感兴趣的:(aop切面日志.多个表达式)