spring AOP(面向切面编程)四种通知类型- xml配置

<!--    配置AOP-->
<aop:config>
<!--    配置切入点表达式 id属性用于指定表达式的唯一标识.expression属性用于指定表达式内容
        此标签写在aop:aspect标签内部只能当前切面使用。
        它还可以写在aop:aspect外面,此时就变成了所有切面可用-->
    <aop:pointcut id="pt1"  expression="execution( * *..*.*(..))"/>
<!--    配置切面-->
    <aop:aspect id="logAdvice" ref="logger">
<!--       配置前置通知:在切入点方方法执行之前执行-->
        <aop:before method="printLog" pointcut-ref="pt1" ></aop:before>
<!--       配置后置通知:在切入点方法正常执行之后值.-->
        <aop:after-returning method="afterReturning" pointcut-ref="pt1"></aop:after-returning>
<!--        配置异常通知:在切入点方法执行产生异常之后执行.它和后置通知只能执行一个-->
        <aop:after-throwing method="atterThrowingProint" pointcut-ref="pt1"></aop:after-throwing>
<!--          配置最终通知:无论切入点方法是否正常执行它都会在其后面执行-->
        <aop:after method="afterPrintLog" pointcut-ref="pt1"></aop:after>
    </aop:aspect>
</aop:config>

猜你喜欢

转载自blog.csdn.net/amazinga/article/details/104569579