1. 程式人生 > >6.AOP配置與應用(xml的方式)

6.AOP配置與應用(xml的方式)

ret bsp epo conf cut span exe service logs

xml 配置 AOP

  1.將 攔截其器對象 初始化到容器中

  2.<aop:config>

    <aop:aspect....

      <aop:pointcut

      <aop:before  

 1 <!-- 使用xml的方式來 完成AOP的配置 -->
 2 <!-- 首先要使用 <aop:config> 標簽來說明下面是關於AOP的配置 -->
 3 <aop:config>
 4     <!-- 定義一個切點的集合,定義在這,可以供所有的切面 來使用 -->
 5     <
aop:pointcut expression="execution(public * com.bjsxt.service..*.add(..))" id="servicePointCut"/> 6 7 <!-- 定義一個切面,該切面的id為 methodAspect,參考 id為 methodInterceptor 的 bean --> 8 <aop:aspect id="methodAspect" ref="methodInterceptor"> 9 10 <!-- 因為參考的是 methodInterceptor 這個bean,所以這裏的 method 指的就是 參考的 bean 的 method
--> 11 <!-- pointcut-ref 說明參考的 pointcut-ref 是哪個 --> 12 <!-- 第一條xml語句的作用是 在 切點集合的方法 執行之前,調用 MethodInterceptor 的 beforeMethod--> 13 14 <aop:before method="beforeMethod" pointcut-ref="servicePointCut"/> 15 <aop:after-returning method
="afterMethod" pointcut-ref="servicePointCut"/> 16 <aop:around method="aroundMethod" pointcut-ref="servicePointCut"/> 17 </aop:aspect> 18 19 </aop:config>

6.AOP配置與應用(xml的方式)