zoukankan      html  css  js  c++  java
  • aop实现接口切面统一处理

    
    import java.util.Arrays;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.aspectj.lang.JoinPoint;
    import org.aspectj.lang.ProceedingJoinPoint;
    import org.aspectj.lang.annotation.AfterReturning;
    import org.aspectj.lang.annotation.AfterThrowing;
    import org.aspectj.lang.annotation.Around;
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Before;
    import org.aspectj.lang.annotation.Pointcut;
    import org.springframework.core.annotation.Order;
    import org.springframework.stereotype.Component;
    
    @Aspect
    @Component
    public class LoggingAspect
    {
        private Log log = LogFactory.getLog(this.getClass());
    
        @Pointcut("execution(* com.abc.xyz.content.service..*(..))")
        protected void loggingOperation()
        {
        }
    
        @Before("loggingOperation()")
        @Order(1)
        public void logJoinPoint(JoinPoint joinPoint)
        {
        log.info("Signature declaring type : " + joinPoint.getSignature().getDeclaringTypeName());
        log.info("Signature name : " + joinPoint.getSignature().getName());
        log.info("Arguments : " + Arrays.toString(joinPoint.getArgs()));
        log.info("Target class : " + joinPoint.getTarget().getClass().getName());
        }
    
        @AfterReturning(pointcut = "loggingOperation()", returning = "result")
        @Order(2)
        public void logAfter(JoinPoint joinPoint, Object result)
        {
        log.info("Exiting from Method :" + joinPoint.getSignature().getName());
        log.info("Return value :" + result);
        }
    
        @AfterThrowing(pointcut = "execution(* com.abc.xyz.content.service..*(..))", throwing = "e")
        @Order(3)
        public void logAfterThrowing(JoinPoint joinPoint, Throwable e)
        {
        log.error("An exception has been thrown in " + joinPoint.getSignature().getName() + "()");
        log.error("Cause :" + e.getCause());
        }
    
        @Around("execution(* com.abc.xyz.content.service..*(..))")
        @Order(4)
        public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable
        {
        log.info("The method " + joinPoint.getSignature().getName() + "() begins with " + Arrays.toString(joinPoint.getArgs()));
        try
        {
            Object result = joinPoint.proceed();
            log.info("The method " + joinPoint.getSignature().getName() + "() ends with " + result);
            return result;
        }
        catch (IllegalArgumentException e)
        {
            log.error("Illegal argument " + Arrays.toString(joinPoint.getArgs()) + " in " + joinPoint.getSignature().getName() + "()");
            throw e;
        }
        }
    
    }
    

     

  • 相关阅读:
    java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Date
    权限控制-JS判断是否有权限进行操作跳转页面需要加target
    为你的网站装个“头像”
    本地存储由来的背景
    HTML5的新的结构元素介绍
    Canvas绘图API
    HTML5文件操作API
    认识HTML5
    基于scrapy爬虫的天气数据采集(python)
    Python strip()方法
  • 原文地址:https://www.cnblogs.com/sunny-miss/p/12891535.html
Copyright © 2011-2022 走看看