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

2023-12-03  本文已影响0人  大也


<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>

上一篇 下一篇

猜你喜欢

热点阅读