zoukankan      html  css  js  c++  java
  • Springboot aop使用

    package com.jxd.Boot.aspect;

    import org.aspectj.lang.JoinPoint;
    import org.aspectj.lang.Signature;
    import org.aspectj.lang.annotation.AfterReturning;
    import org.aspectj.lang.annotation.AfterThrowing;
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Before;
    import org.aspectj.lang.annotation.Pointcut;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.stereotype.Component;

    /**
    * @ClassName LoggingAspect
    * @Description 日志切面
    * @author jxd
    * @Date 2018年6月4日 上午9:34:18
    * @version 1.0.0
    */
    @Aspect
    @Component
    public class LoggingAspect {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Pointcut(value = "execution(public * com.jxd.Boot.web.*.*(..))")
    public void webLog() {
    }

    /**
    * @Description (前置通知)
    * @param joinpoint
    */
    @Before("webLog()")
    public void dobefor(JoinPoint joinpoint) {
    Signature signature = joinpoint.getSignature();
    String typename = signature.getDeclaringTypeName();
    String name = signature.getName();
    logger.info("......................." + typename + "." + name + "()"
    + "方法进入.......................");
    }

    /**
    * @Description (后置通知)
    * @param ret
    */
    @AfterReturning(returning = "ret", pointcut = "webLog()")
    public void doafter(Object ret) {
    logger.info("......................." + "返回值:" + ret+".......................");
    }

    /**
    * @Description (异常通知)
    * @param joinpoint
    * @param e
    */
    @AfterThrowing(value = "webLog()", throwing = "e")
    public void afterexcetion(JoinPoint joinpoint, Exception e) {
    Signature signature = joinpoint.getSignature();
    String typename = signature.getDeclaringTypeName();
    String name = signature.getName();
    logger.info("......................." + typename + "." + name + "()"+"方法异常:"+e+".......................");
    }

    }

  • 相关阅读:
    SHELL 基本语法
    SHELL 入门
    Kahana::Cache
    AUTH 用户管理操作
    继承和委托关系
    ORM 构造和add 方法
    游标的使用
    有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?
    01背包 模板1
    poj 2533
  • 原文地址:https://www.cnblogs.com/coderdxj/p/9133433.html
Copyright © 2011-2022 走看看