简单的AOP标签

时间:2023-03-10 03:04:50
简单的AOP标签

常用标签

1.1<aop:config>

//作用  用于声明aop的配置
//配置:<aop:config></aop:config>

1.2 <aop:aspect>

/*
作用:
用于配置切面。
属性:
id:给切面提供一个唯一标识。
ref:引用配置好的通知类bean的id。
配置:<aop:aspect id="logAdvice" ref="logger"> */

1.3<aop:pointcut>

/*
作用:
用于配置切入点表达式
属性:
expression:用于定义切入点表达式。
id:用于给切入点表达式提供一个唯一标识。
配置:<aop:pointcut expression="execution(* cn.itcast.service.impl.*.*(..))" id="pt1"/> */

1.4<aop:before>

/*
作用:
用于配置前置通知
属性:
method:指定通知中方法的名称。
pointct:定义切入点表达式
pointcut-ref:指定切入点表达式的引用
配置:<aop:before method="beforePrintLog" pointcut-ref="pt1"/>
*/

1.5<aop:after-returning>

/*
作用:
用于配置后置通知
属性:
method:指定通知中方法的名称。
pointct:定义切入点表达式
pointcut-ref:指定切入点表达式的引用
配置:
<aop:after-returning method="afterReturningPrintLog" pointcut-ref="pt1"/>
*/

1.6<aop:after-throwing>

/*
作用:
用于配置异常通知
属性:
method:指定通知中方法的名称。
pointct:定义切入点表达式
pointcut-ref:指定切入点表达式的引用
配置:<aop:after-throwing method="afterThrowingPrintLog" pointcut-ref="pt1"/>
*/

1.7 <aop:after>

/*
作用:
用于配置最终通知
属性:
method:指定通知中方法的名称。
pointct:定义切入点表达式
pointcut-ref:指定切入点表达式的引用
配置:<aop:after method="afterPrintLog" pointcut-ref="pt1"/>
*/

1.8<aop:around>

/*
作用:
用于配置环绕通知
属性:
method:指定通知中方法的名称。
pointct:定义切入点表达式
pointcut-ref:指定切入点表达式的引用
配置:<aop:around method="transactionAround" pointcut-ref="pt1"/>
说明:
它是spring框架为我们提供的一种可以在代码中手动控制增强代码什么时候执行的方式。
注意:
通常情况下,环绕通知都是独立使用的
*/