13_Spring_AOPXML方式实现_了解

01way / 2023-07-30 / 原文

13_Spring_AOPXML方式实现_了解

1、创建两个类,增强类和被增强类,创建方法

见之前的代码

2、在spring配置文件中创建两个类对象

  1.  

3、在spring配置文件中配置切入点

  1.  <aop:config>
    
  2.      <!--切入点-->
    
  3.      <aop:pointcut id="pointCutAdd" expression="execution(*
    
    com.msb.dao.UserDao.add*(..))"/>
  4.      <!--配置切面-->
    
  5.      <aop:aspect ref="daoAspect">
    
  6.          <!--增强作用在具体的方法上-->
    
  7.          <aop:before method="methodBefore" pointcut-ref="pointCutAdd"/>
    
  8.          <aop:after method="methodAfter" pointcut-ref="pointCutAdd"/>
    
  9.         <aop:around method="methodAround" pointcut-ref="pointCutAdd"/>
    
  10.         <aop:after-returning method="methodAfterReturning" 
    
    pointcut-ref="pointCutAdd" returning="res"/>
  11.         <aop:after-throwing method="methodAfterThrowing" 
    
    pointcut-ref="pointCutAdd" throwing="ex"/>
  12.     </aop:aspect>
    
  13. </aop:config> 
    

Generated with Mybase Desktop 8.2.13