• 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+".......................");
    }

    }

  • 相关阅读:
    162. Find Peak Element
    475. Heaters
    字符串统计
    数据的交换输出
    偶数求和
    青年歌手大奖赛_评委会打分
    蟠桃记
    素数判定
    多项式求和
    出现Presentation Error的解决方法
  • 原文地址:https://www.cnblogs.com/coderdxj/p/9133433.html
Copyright © 2020-2023  润新知