您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
11-xml方式实现aop-切点表达式的抽取
发布时间:2025-01-18 13:01:59编辑:雪饮阅读()
-
切点表达式的抽取可以解决在Spring配置文件中定义切点的时候每次写重复的切点表达式,除非每次的切点的表达式不同。
例如这是之前声明切面的三个切点
<!--声明切面-->
<aop:aspect ref="myAspect">
<aop:around method="around" pointcut="execution(* sp21.aop.Target.save())"/>
<aop:after-throwing method="afterThrowing" pointcut="execution(* sp21.aop.Target.save())"/>
<aop:after method="after" pointcut="execution(* sp21.aop.Target.save())"/>
</aop:aspect>
那我可以简化成
<!--声明切面-->
<aop:aspect ref="myAspect">
<!--单独定义切点表达式-->
<aop:pointcut id="myPointCut" expression="execution(* sp21.aop.Target.save())"/>
<aop:around method="around" pointcut-ref="myPointCut"/>
<aop:after-throwing method="afterThrowing" pointcut-ref="myPointCut"/>
<aop:after method="after" pointcut-ref="myPointCut"/>
</aop:aspect>
关键字词:切点表达式,抽取