美文网首页
5.3.Spring AOP基于XML方式实现(了解)

5.3.Spring AOP基于XML方式实现(了解)

作者: 大也 | 来源:发表于2023-12-03 16:16 被阅读0次
    • test文件顶部配置
    • @SpringJUnitConfig(locations = "spring.xml")
    • TODO: xml配置
    • <?xml version="1.0" encoding="UTF-8"?>
    • <beans xmlns="http://www.springframework.org/schema/beans"
    • xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      
    • xmlns:context="http://www.springframework.org/schema/context"
      
    • xmlns:aop="http://www.springframework.org/schema/aop"
      
    • xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd">
      
    • <!-- 进行包扫描-->
      
    • <context:component-scan base-package="com.atguigu"/>
      
    • <!-- 开启aspectj框架注解支持 //开启aspect aop-->
      
    •         <aop:aspectj-autoproxy/>
      
    • </beans>
    */


<bean id="calculatorPure" class="com.atguigu.aop.imp.CalculatorPureImpl"/>


<bean id="logAspect" class="com.atguigu.aop.aspect.LogAspect"/>


<aop:config>

<!-- 配置切入点表达式 -->
<aop:pointcut id="logPointCut" expression="execution(* *..*.*(..))"/>

<!-- aop:aspect标签:配置切面 -->
<!-- ref属性:关联切面类的bean -->
<aop:aspect ref="logAspect">
    <!-- aop:before标签:配置前置通知 -->
    <!-- method属性:指定前置通知的方法名 -->
    <!-- pointcut-ref属性:引用切入点表达式 -->
    <aop:before method="printLogBeforeCore" pointcut-ref="logPointCut"/>

    <!-- aop:after-returning标签:配置返回通知 -->
    <!-- returning属性:指定通知方法中用来接收目标方法返回值的参数名 -->
    <aop:after-returning
            method="printLogAfterCoreSuccess"
            pointcut-ref="logPointCut"
            returning="targetMethodReturnValue"/>

    <!-- aop:after-throwing标签:配置异常通知 -->
    <!-- throwing属性:指定通知方法中用来接收目标方法抛出异常的异常对象的参数名 -->
    <aop:after-throwing
            method="printLogAfterCoreException"
            pointcut-ref="logPointCut"
            throwing="targetMethodException"/>

    <!-- aop:after标签:配置后置通知 -->
    <aop:after method="printLogCoreFinallyEnd" pointcut-ref="logPointCut"/>

    <!-- aop:around标签:配置环绕通知 -->
    <!--<aop:around method="……" pointcut-ref="logPointCut"/>-->
</aop:aspect>

</aop:config>

相关文章

网友评论

      本文标题:5.3.Spring AOP基于XML方式实现(了解)

      本文链接:https://www.haomeiwen.com/subject/zkwawdtx.html