6.AOP配置与应用(xml的方式)

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>
原文地址:https://www.cnblogs.com/xuzekun/p/7399331.html