码迷,mamicode.com
首页 > 其他好文 > 详细

xml实现AO

时间:2016-06-07 23:54:42      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:

1.使用<aop:config></aop:config>

2.首先我们需要配置<aop:aspect></aop:aspect>,就是配置切面

  2.1首先配置切面的id,也就是切面叫什么名称,我们起名字为id="myLogAspect"

  2.2我们的切面是由哪一个类来做的,ref="logAspect",ref属性值是spring所管理的类(bean)

3.配置pointcut,下面需要配置,我们要在哪一些类里面加入这些操作。或者说在那些类里面加入切面,id=""指明我们是在哪些类中加入,expression

  3.1<aop:pointcut id="logPointCut" expression="execution(* org.zttc.itat.spring.dao.*.add*(..))||

                                                                          execution(* org.zttc.itat.spring.dao.*.delete*(..))||

                                                                          execution(* org.zttc.itat.spring.dao.*.update*(..))" />

4.配置before,method=""指明,我们要调用的是切面(切面是ref="logAspect",前面已经配置过了)里面的哪一个方法 ,point-ref=""表明我们要引入哪一个PointCut(id="logPointCut",前面也已经配置过了),也就是说我们的logStart方法会在pointcut中配置的那些类中的那些方法中加入。

  4.1<aop:before method="logStart" point-ref="logPointCut">

  4.2<aop:before method="logEnd" point-ref="logPointCut">

  4.3<aop:before method="logAround" point-ref="logPointCut">

 

注解和xml哪个方便一些?

  使用注解的时候,我们需要为每一个method(before,after,around)都配置exexution,而使用xml我们只需要配置一次就可以了,从而xml更方便

xml实现AO

标签:

原文地址:http://www.cnblogs.com/mrxiaohe/p/5568509.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!