spring学习----aop配置demo
来源:互联网 发布:json 汉字 编辑:程序博客网 时间:2024/06/16 09:08
注意
aop:aspect 切面类是普通类即可 aop:advisor 切面类必须实现 advice接口 如:MethodBeforeAdvice AfterReturningAdvice等
定义通知(实现Advice)
public class MyAfterAdvice implements AfterReturningAdvice { @Override public void afterReturning(Object o, Method method, Object[] objects, Object o1) throws Throwable { System.out.println("=========我是afterReturn通知方法============="); }}
public class MyBeforeAdvice implements MethodBeforeAdvice{ @Override public void before(Method method, Object[] objects, Object o) throws Throwable { System.out.println("=========我是前置通知方法============="); }}
普通通知(不实现Advice)
public class MyNoAdvice { public void before() throws Throwable { System.out.println("=============我的普通的before前置方法===================="); } public void after() throws Throwable { System.out.println("=============我的普通的After后置方法===================="); }}
业务类
public interface IBussinessService { void bussiness(); void sayHello();}
public class BussinessServiceImpl implements IBussinessService{ @Override public void bussiness() { System.out.println("=========我是业务方法=========="); } @Override public void sayHello() { System.out.println("=========我是say Hello=========="); }}
测试类
@Test public void test1(){ ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:beans.xml"); IBussinessService bussinessService = applicationContext.getBean("bussinessService",IBussinessService.class); bussinessService.bussiness(); }
配置文件
<!-- ==========================测试AOP============================= --> <bean id="myBeforeAdvice" class="com.chenfei.advice.MyBeforeAdvice"></bean> <bean id="myAfterAdvice" class="com.chenfei.advice.MyAfterAdvice"></bean> <bean id="myNoAdvice" class="com.chenfei.advice.MyNoAdvice"/> <bean id="bussinessService" class="com.chenfei.service.impl.BussinessServiceImpl"></bean> <aop:config> <aop:pointcut id="pointtest1" expression="execution(* com.chenfei.service.impl.*.*(..))" /> <aop:aspect ref="myNoAdvice"> <aop:before method="before" pointcut-ref="pointtest1"/> <aop:after method="after" pointcut-ref="pointtest1"/> </aop:aspect> </aop:config> <aop:config> <aop:pointcut id="pointtest2" expression="execution(* com.chenfei.service.impl.*.*(..))" /> <aop:advisor pointcut-ref="pointtest2" advice-ref="myBeforeAdvice" /> <aop:advisor pointcut-ref="pointtest2" advice-ref="myAfterAdvice" /> </aop:config>
测试结果
阅读全文
0 0
- spring学习----aop配置demo
- Spring AOP---基于Xml配置应用demo
- SSH Web Demo Spring 配置 AOP
- Spring Aspectj AOP配置学习
- Spring-AOP配置(学习笔记)
- spring aop注解Demo
- Spring AOP入门Demo
- Spring AOP 简单demo
- Spring AOP Demo
- Spring Aop Demo
- Spring Aop demo
- Spring Aop demo入门
- Spring学习:AOP配置1(xml)
- Spring学习之使用注解配置AOP
- Spring学习之使用XML配置AOP
- Spring aop 小实例demo
- Spring AOP应用实例demo
- spring aop切面编写demo
- Codeforces】-445C-DZY Loves Physics
- 将javaBean转换成XML
- GCC学习日志
- worldwind 地图显示字体修改
- C++删除单链表中值重复的结点
- spring学习----aop配置demo
- HDU 3247-Resource Archiver(AC自动机+BFS+DP)
- 学习Spring必学的Java基础知识(2)----动态代理
- opencv感兴趣区图像叠加
- powerdesigner向MySQL导入数据
- H5中启动Android app
- CentOS7mini配置Tomcat
- hdu 6096 String 字典树
- Object主要方法的总结