您的位置:首页 > 编程语言 > Java开发

spring基础----->aop全配置下的配置切入点

2017-02-25 23:22 375 查看
1.当我们不使用注解@pointcut来进行配置切入点,以xml配置方式如何去表达切入点了?

答:Xml配置切入点,由两个标签起作用:

1.1<aop:config....>标签下的<aop:pointcut>标签,

1.2<aop:aspect...>标签下的<aop:pointcut>标签.

2.一般情况下我们都是结合使用<aop:config>和<aop:aspect>下的pointcut标签

    如何结合使用?

    答:<aop:config>标签有两个属性:  id和 expression  如:<aop:pointcut id="mypointcut" expression="execution(* test.*.*(..))"/> 在此情况下mypointcut就可以代表execution(* test.*.*(..))切入表达式,然后在<aop:aspect...>标签下使用pointcut-ref="mypointcut" 就可以引用,那么他们就达到了结合使用的效果

  

   分别使用的话

   <aop:config>下的pointcut就显得非常无力了,因为它可以反复被引用,而且它也是为了被引用而写的

   <aop:aspect>下的pointcut是在当前的通知语句里面起作用  如:<aop:before pointcut=""execution(* test.*.*(..))" method=""> 出去该标签则无效了!

3.结合使用<aop:config>和<aop:aspect>的pointcut标签案例(全xml配置无注解)

  <aop:config>

                  <aop:pointcut  id="mypointcut" expression="execution(* aoptest.*.*(..))"/>

                  <aop:aspect id="aspectid" ref="aspect">

                      <aop:before  pointcut-ref="mypointcut" method="play"/>

                  </aop:aspect>

          </aop:config>

           

           

           <bean id="person" class="aoptest.person"/>

           <bean id="aspect" class="aoptest.aspect"/>

           

          </beans>

今天学习xml配置切入点到此为止!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: