Spring(六)---面向切面编程(2)

(五)在XML中声明切面
Spring的AOP配置原素能够以非侵入性的方式声明切面

AOP配置元素用途
<aop:advisor>定义AOP通知器
<aop:after>定义后置通知
<aop:after-returning>定义AOP返回通知
<aop:after-throwing>定义AOP异常通知
<aop:around>定义AOP环绕通知
<aop:aspect>定义一个切面
<aop:aspectj-autoproxy>启用@AspectJ注解驱动的切面
<aop:before>定义AOP前置通知
<aop:config>顶层的AOP配置元素.大多数的<aop:*>元素必须包含在<aop:config>内
<aop:declare-parent>以透明的方式为被通知的对象引入额外的接口
<aop:pointcut>定义一个切点
//例:
<bean id="audience1" class="com.ty.xml.Audience1"></bean>
 <aop:config>
 //定义切面
   <aop:aspect ref="audience1">
   //定义通用的切点表达式
//定义前置通知
      <aop:before method="silenceCellPhones" pointcut-ref="pointcut"/>
      <aop:before method="takeSeats" pointcut-ref="pointcut"/>
      //定义后置通知
      <aop:after-returning method="applause" pointcut="execution(* com.ty.concert.*.perform(..))"/>
      //定义异常通知
      <aop:after-throwing method="demandRefund" pointcut="execution(* com.ty.concert.*.perform(..))"/>
      //引入通知
      <aop:declare-parents types-matching="com.ty.concert.Performance+" implement-interface="com.ty.concert.Encoreable"
       default-impl="com.ty.concert.DefaultEncoreable" ></aop:declare-parents>
       //若IOC容器中存在DefaultEncoreable对应的bean
      <aop:declare-parents types-matching="com.ty.concert.Performance+" implement-interface="com.ty.concert.Encoreable"
       default-ref="defaultEncoreable" ></aop:declare-parents> 
   </aop:aspect>
 </aop:config>

(六)注入AspectJ切面
参考:http://blog.csdn.net/u012523359/article/details/72851479

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值