spring 学习笔记 使用pojo+xml的方式开发aop
2013-02-28 12:37
826 查看
如果采用pojo+xml的方式,切面中不用在引用ModifyDate
环绕通知:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"> <!-- 观众 --> <bean id="audience" class="study.spring.aop.pojoxml.Audience"></bean> <!-- 演员 --> <bean id="singer" class="study.spring.aop.pojoxml.Singer"></bean> <aop:config> <aop:aspect ref="audience"> <aop:declare-parents types-matching="study.spring.aop.pojoxml.Singer" implement-interface="study.spring.aop.pojoxml.ModifyDate" default-impl="study.spring.aop.pojoxml.ModifyDateImpl"/> <aop:pointcut expression="execution(* study.spring.aop.pojoxml.Performer.*(..))" id="audiencePontcut"/> <aop:before method="setting" pointcut-ref="audiencePontcut"/> <aop:before method="turnOffCellphone" pointcut-ref="audiencePontcut"/> <!-- 后置通知 --> <aop:after-returning method="applaud" pointcut-ref="audiencePontcut" returning="ret"/> <!-- 抛出异常通知 --> <aop:after-throwing method="hiss" pointcut-ref="audiencePontcut" throwing="e"/> <!-- finally通知 --> <aop:after method="goHome" pointcut-ref="audiencePontcut"/> </aop:aspect> </aop:config> </beans>
环绕通知:
public class Audience { public Object watch(ProceedingJoinPoint pjp){ try { System.out.println("setting"); System.out.println("turnOffCellphone"); Object ret = pjp.proceed(); System.out.println("applaud"); return ret ; } catch (Throwable e) { System.out.println("paymentRefund"); e.printStackTrace(); } finally{ System.out.println("goHome"); } return null ; } }
<?xml version="1.0"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd "> <!-- 观众 --> <bean id="audience" class="study.spring.aop.pojoxml.around.Audience" /> <!-- 歌手 --> <bean id="singer" class="study.spring.aop.pojoxml.around.Singer" /> <!-- aop配置,将pojo配置成切面--> <aop:config> <aop:aspect ref="audience"> <!-- 定义切入点 --> <aop:pointcut expression="execution(* cn.itcast.spring.aop.pojoxml.around.Performer.*(..))" id="audiencePontcut"/> <aop:around method="watch" pointcut-ref="audiencePontcut"/> </aop:aspect> </aop:config> </beans>
相关文章推荐
- spring学习笔记12----Spring+jdbc组合开发( 采用基于xml方式配置事务)
- spring学习笔记7--使用spring进行面向切面的(AOP)编程(1)注解方式实现
- ITCAST视频-Spring学习笔记(使用Spring的注解方式实现AOP的细节)
- spring 学习笔记 使用aspectj开发aop
- Spring学习笔记(14)----使用Spring的注解方式实现AOP
- spring框架的学习(五)——Spring使用AspectJ进行AOP的开发:注解方式
- Spring学习-22:Spring的AOP:基于AspectJ的XML配置方式开发
- ITCAST视频-Spring学习笔记(使用Spring的注解方式实现AOP入门)
- Spring学习历程---使用注解方式入门AOP
- java学习笔记10 - 以@AspectJ方式在Spring中实现AOP
- Spring4学习笔记-AOP(基于配置文件的方式)
- 使用pojo+xml开发aop案例
- Spring2.5注解(标注)学习笔记(使用annotation代替XML)
- Spring学习笔记(14)----使用CGLIB实现AOP功能
- spring aop的使用(注解方式以及基于xml配置方式)
- SpringMVC学习笔记(二)使用IntelliJ IDEA开发Spring MVC HelloWorld(基于Maven)
- Spring AOP使用Aspectj基于xml方式,初始化Bean参数
- Java学习笔记39:Spring XML使用
- 重温Spring之旅6——基于XML配置方式进行AOP开发
- Spring学习笔记 —— AOP(面向切面编程) 之使用ProxyFactoryBean实现AOP