AspectJ之Advice定义之Before Advice
来源:互联网 发布:非农数据公布日期 编辑:程序博客网 时间:2024/05/29 04:30
1、Before Advice:
示例步骤如下:
1、配置文件如下:
<context:component-scan base-package="com.wuyonghu" /> //这里的aop:aspectj-autoproxy标签必须有,否则无效,相当于是aspectj的自动代理 <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
2、定义切面类:
package com.wuyonghu.aspectj;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.springframework.stereotype.Component;@Component("aspect")@Aspectpublic class MoocAspect { @Before("execution(* com.wuyonghu.aspectj.AspectjBiz.*(..))") public void before(){ System.out.println("切面类中的before方法执行了。。。"); }}
3、定义业务类:
package com.wuyonghu.aspectj;import org.springframework.stereotype.Service;@Servicepublic class AspectjBiz { public String save(String arg){ System.out.println("AspectBiz中的save方法执行了"); return "success"; }}
4、测试类:
package com.wuyonghu.aspectj;import org.junit.Test;import org.junit.runner.RunWith;import org.junit.runners.BlockJUnit4ClassRunner;import org.springframework.context.support.ClassPathXmlApplicationContext;@RunWith(BlockJUnit4ClassRunner.class)public class AspectjTest { @Test public void test1() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); AspectjBiz biz=(AspectjBiz) context.getBean("aspectjBiz"); biz.save("海賊王"); }}
0 0
- AspectJ之Advice定义之Before Advice
- AspectJ之Advice定义之finally advice
- AspectJ之Advice定义之Around advice
- AspectJ之Advice定义之After returning advice
- AspectJ之Advice定义之After throwing advice
- AspectJ之 Advice扩展
- AspectJ学习笔记之Advice
- 跟我学aspectj之九----- advice
- Spring2.0 AOP 之Before,After,Thrown,Around Advice(一)
- Spring2.0 AOP 之Before,After,Thrown,Around Advice(二)
- Jboss AOP之Advice
- Spring AOP之Advice
- Spring之Advice小结
- Advice
- advice
- advice
- Spring入门(AspectJ,Advice以及对于Advice扩展)
- Spring之Advice应用(上)
- 类似点赞、评论
- 关于Fragment的一些处理
- MyEclispe导出不了jar包
- 第十五周 OJ 连接两个字符串
- 合并两个排序的链表
- AspectJ之Advice定义之Before Advice
- sprite遇到的一个慢慢显示问题
- 双向循环链表的建立、查找、添加、删除
- 修改版
- Debug一些经验
- 点击图片出现图片(以弹框方式显示)
- 区块链:去中心化的交易所方向
- MacOS X下开启root用户
- push时隐藏tabbar