【sping揭秘】15、afterreturning
2018-06-18 01:39:15来源:未知 阅读 ()
@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(); }

标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 揭秘阿里、腾讯、字节跳动在家办公的区别 2020-02-24
- 记录下spingboot连接阿里云服务器上的MySQL数据库报错 2020-02-06
- sping MVC 定时任务的设置 2020-01-05
- spingboot中使用scheduled设置定时任务注意事项 2020-01-02
- 【玩转SpringBoot】给自动配置来个整体大揭秘 2019-12-19
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
