<?xml version="1.0" encoding="UTF-8"?>
<bean id="taget" class="com.itheima.aop.Target"></bean>
<!-- 创建一个bean对象,类型为com.itheima.aop.下的MyAspect类-->
<!-- 等于是获得一个MyAspect类的对象-->
<bean id="myAspect" class="com.itheima.aop.MyAspect"></bean>
<!--配置织入:执行切点方法时,需要配置的一起跟着执行增强方法(前置、后置...)-->
<aop:config>
<!--aspect ref="切面类名",指定切面类,增强方法只能创建在切面类里面-->
<aop:aspect ref="myAspect">
<!--抽取切点表达式-->
<aop:pointcut id="myPointcut" expression="execution(* com.itheima.aop.Target.*(..))"></aop:pointcut>
<aop:around method="around" pointcut-ref="myPointcut"/>
<!-- after-throwing是后置通知通知方法(增强方法一种),method是指定一个方法,让这个方法按着后置通知方法的形式去执行-->
<!-- 等于是一个事件,一旦有切点方法被调用,触发后置通知方法事件,就执行这个method属性指定的方法"before"-->
<!-- 通知方法必须是切面类里的方法-->
<!-- pointcut-ref指定本环绕通知方法跟随一起执行的切点方法,-->
<!-- myPointcut是上面定义的切点表达式标签的ID名-->
<aop:after-throwing method="before" pointcut-ref="myPointcut"/>
</aop:aspect>
</aop:config>
本文介绍了一种使用XML配置的方式实现面向切面编程(AOP)。具体包括如何定义切点、切面以及各种通知类型(如前置、后置、环绕等)。通过具体的配置示例展示了如何将增强逻辑织入到目标方法的执行流程中。
4827

被折叠的 条评论
为什么被折叠?



