@Component
@Aspect
@Slf4j
public class OperationAspect {
@Pointcut("execution(* com.sumavision.sums.controller.*.*(..)))")
public void option() {
}
@AfterThrowing(pointcut = "option()",throwing ="e")
public Result returnThrowable(JoinPoint joinPoint,Exception e) {
log.debug("throwable start...");
log.error(e.getMessage(),e);
//获取方法
Method method = getMethod(joinPoint);
//获取方法的注解
Annotation[] annotations = method.getAnnotations();
//处理注解
throw new OperationException(AspectUtil.analyzeAnnotation(annotations)+"异常");
}
private Method getMethod(JoinPoint joinPoint) {
//获取方法签名
Signature signature = joinPoint.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
//获取方法
return methodSignature.getMethod();
}
}