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

    }

  • 相关阅读:
    【NOIP2018】游记
    题解 P1441 【砝码称重】
    题解 P3128 【[USACO15DEC]最大流Max Flow】
    题解 P1949 【聪明的打字员_NOI导刊2011提高(10)】
    题解 P1966 【火柴排队】
    题解 P1895 【数字序列】
    topcoder做题
    1149E
    hdu 6589
    hdu 6579
  • 原文地址:https://www.cnblogs.com/coderdxj/p/9133433.html
Copyright © 2011-2022 走看看