Beispiel #1
0
  @Around(value = "studentDao() || systemDao() || coreDao() ")
  public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    long startTime = System.currentTimeMillis();
    Object proceed = proceedingJoinPoint.proceed();
    long endTime = System.currentTimeMillis();

    // 拦截的实体类
    String className = proceedingJoinPoint.getTarget().getClass().getName();
    // 拦截的方法名称
    String methodName = proceedingJoinPoint.getSignature().getName();

    SystemLogger systemLogger = new SystemLogger();
    systemLogger.setType(CodeConstant.LOGGER_TYPE_DAO);
    systemLogger.setClassName(className);
    systemLogger.setMethordName(methodName);
    systemLogger.setExecuteTime((int) (endTime - startTime));
    LoggerUtil.log(systemLogger);
    return proceed;
  }
Beispiel #2
0
  /**
   * Dao内方法抛出异常运行下面方法
   *
   * @param joinPoint
   * @param e
   */
  @AfterThrowing(value = "studentDao() || systemDao() || coreDao() ", throwing = "e")
  public void afterThrow(JoinPoint joinPoint, Exception e) {
    StringBuffer stackTrace = new StringBuffer();
    stackTrace.append(e.getClass().getName()).append(": ").append(e.getMessage()).append("\r\n\t");
    for (StackTraceElement stackTraceElement : e.getStackTrace()) {
      stackTrace.append(stackTraceElement.toString()).append("\r\n\t");
    }

    // 拦截的实体类
    String className = joinPoint.getTarget().getClass().getName();
    // 拦截的方法名称
    String methodName = joinPoint.getSignature().getName();

    ExceptionLogger exceptionLogger = new ExceptionLogger();
    exceptionLogger.setType(CodeConstant.LOGGER_TYPE_DAO);
    exceptionLogger.setClassName(className);
    exceptionLogger.setMethordName(methodName);
    exceptionLogger.setMessage(e.getMessage());
    exceptionLogger.setStackTrace(stackTrace.toString());
    exceptionLogger.setUserId(UserUtil.getUser().getUserId());
    LoggerUtil.log(exceptionLogger);
  }