工作流程图
核心模块
@Autowired
private ExceptionHandle exceptionHandle;
@Pointcut("@annotation(*)")
public void log() {}
@Around("log()")
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
try {
proceedingJoinPoint.proceed();
} catch (Exception e) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
Logs.error.error("url={}",request.getRequestURL());
//method
Logs.error.error("method={}",request.getMethod());
//ip
Logs.error.error("id={}",request.getRemoteAddr());
//class_method
Logs.error.error("class_method={}",proceedingJoinPoint.getSignature().getDeclaringTypeName() + "," + proceedingJoinPoint.getSignature().getName());
//args[]
Logs.error.error("args={}",proceedingJoinPoint.getArgs());
throw e;
}
return null;
}
@ExceptionHandler(value = Exception.class)
@ResponseBody
public Result<?> exceptionGet(Exception e){
if(e instanceof DescribeException){
DescribeException MyException = (DescribeException) e;
return Result.fail(MyException.getCode(),MyException.getMessage());
}
Logs.error.error("【系统异常】",e);
return Result.fail(ExceptionEnum.UNKNOW_ERROR);
}
上面就是一些核心模块,只需要自定义注解和异常类便可实现异常的自动捕获了