@Test void logExecutionTime() { userService.addUser("xiaoming"); assertThrows(NullPointerException.class, () -> userService.addUser("小明", 123)); }
@Around("pointcut() && @annotation(monitor)") public Object logExecutionTime(ProceedingJoinPoint joinPoint, MethodMonitor monitor) throws Throwable { MethodMonitor.LogPrintLogic logPrintLogic; try { logPrintLogic = context.getBean(monitor.logic()); }catch (Exception ex){ log.error("未找到日志打印逻辑： {}， 将使用默认逻辑打印日志！", monitor.logic()); logPrintLogic = context.getBean(DefaultLogPrintLogic.class); } return logPrintLogic.build(joinPoint); }
MethodMonitorProcessor { @Around("pointcut() && @annotation(monitor)") public Object logExecutionTime(ProceedingJoinPoint joinPoint, MethodMonitor monitor) throws Throwable { MethodMonitor.LogPrintLogic logPrintLogic; try { logPrintLogic = context.getBean(monitor.logic()); }catch (Exception ex){ log.error("未找到日志打印逻辑： {}， 将使用默认逻辑打印日志！", monitor.logic()); logPrintLogic = context.getBean(DefaultLogPrintLogic.class); } return logPrintLogic.build(joinPoint); } }
MethodMonitorProcessor { @Around("pointcut() && @annotation(monitor)") public Object logExecutionTime(ProceedingJoinPoint joinPoint, MethodMonitor monitor) throws Throwable { MethodMonitor.LogPrintLogic logPrintLogic; try { logPrintLogic = context.getBean(monitor.logic()); }catch (Exception ex){ log.error("未找到日志打印逻辑： {}， 将使用默认逻辑打印日志！", monitor.logic()); logPrintLogic = context.getBean(DefaultLogPrintLogic.class); } return logPrintLogic.build(joinPoint); }  }
MethodMonitorProcessor { @Around("pointcut() && @annotation(monitor)") public Object logExecutionTime(ProceedingJoinPoint joinPoint, MethodMonitor monitor) throws Throwable { MethodMonitor.LogPrintLogic logPrintLogic; try { logPrintLogic = context.getBean(monitor.logic()); }catch (Exception ex){ log.error("未找到日志打印逻辑： {}， 将使用默认逻辑打印日志！", monitor.logic()); logPrintLogic = context.getBean(DefaultLogPrintLogic.class); } return logPrintLogic.build(joinPoint); }  @Around("pointcut() && @annotation(monitor)") Object logExecutionTime(ProceedingJoinPoint joinPoint, MethodMonitor monitor); @Bean DefaultLogPrintLogic logPrintLogic(); }
MethodMonitorProcessor { @Around("pointcut() && @annotation(monitor)") public Object logExecutionTime(ProceedingJoinPoint joinPoint, MethodMonitor monitor) throws Throwable { MethodMonitor.LogPrintLogic logPrintLogic; try { logPrintLogic = context.getBean(monitor.logic()); }catch (Exception ex){ log.error("未找到日志打印逻辑： {}， 将使用默认逻辑打印日志！", monitor.logic()); logPrintLogic = context.getBean(DefaultLogPrintLogic.class); } return logPrintLogic.build(joinPoint); }  @Around("pointcut() && @annotation(monitor)") Object logExecutionTime(ProceedingJoinPoint joinPoint, MethodMonitor monitor); @Bean DefaultLogPrintLogic logPrintLogic();  }