zoukankan      html  css  js  c++  java
  • 【sping揭秘】15、afterreturning

    @afterreturning

    我们同理写几个测试类

    package cn.cutter.start.bean;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.stereotype.Component;
    
    @Component
    public class AterReturningTestBean {
    
        private static final Log logger = LogFactory.getLog(AterReturningTestBean.class);
    
        public void aterReturningTest() {
            logger.info("aterReturningTest sds");
        }
        
        public int aterReturningTestInt() {
            logger.info("aterReturningTestInt");
            
            return 666;
        }
        
    }

    写几个测试的拦截器

    package cn.cutter.start.aop;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.aspectj.lang.annotation.AfterReturning;
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Pointcut;
    import org.springframework.stereotype.Component;
    
    /**
     * 
     * @author xiaof
     *
     */
    @Component
    @Aspect
    public class AterReturningAspect {
    
        private static final Log logger = LogFactory.getLog(AterReturningAspect.class);
        
        //execution(* cn.cutter.start.bean.BeofreTestBean.*(..))
        @Pointcut("execution(* cn.cutter.start.bean.AterReturningTestBean.*(..))")
        private void pointCut1() {}
        
        @AfterReturning(pointcut="pointCut1()", returning="value1")
        public void testReturn1(int value1) {
            
            logger.info("返回拦截:" + value1);
            
        }
        
        @AfterReturning(pointcut="pointCut1()")
        public void testReturn2() {
            
            logger.info("返回拦截:没有参数");
            
        }
        
    }

    结果:

    @Test
        public void testAop4() {
            ApplicationContext ctx = this.before();
            
            AterReturningTestBean att = (AterReturningTestBean) ctx.getBean("aterReturningTestBean");
            
    //        att.aterReturningTest();
            
            att.aterReturningTestInt();
            
        }

  • 相关阅读:
    qml: QtCharts模块得使用(数据整合和显示) ---- <二>
    qml: QtCharts模块的使用(基本配置)------<一>
    【转载】Qt之JSON生成与解析
    qml: 支持的基本类型
    opencv: 基本知识;
    qml: 模块定义与使用
    Android studio开发中遇到的错误
    阅读笔记——《人月神话》5
    Android studio Adapter基础
    Android studio Date & Time组件2
  • 原文地址:https://www.cnblogs.com/cutter-point/p/8977821.html
Copyright © 2011-2022 走看看