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更方便

posted on 2016-06-07 22:21  Mr.He多多指教  阅读(502)  评论(0编辑  收藏  举报