Spring中AOP(通知)的使用

1、新建 Spring Bean Configuration File  xml格式的文件

2、 xml文件

<bean id="my1" class="xml.MyJiSQ"></bean>

<!-- 把切面类接入容器 -->
<bean id="log" class="xml.LogAspect"></bean>

<bean id="check" class="xml.CheckAspect"></bean>

<aop:config>

<!-- 定义切面类 -->
<aop:aspect ref="log" order="2">

<!-- 定义公共切点 -->
<aop:pointcut expression="execution(* xml.*.*(..))"  id="pc_log"/>

<!-- 定义通知 -->
<!-- 前置通知 -->
<aop:before method="beforeLog" pointcut="execution(* xml.*.*(..))"/>
<!-- 后置通知 -->
<aop:after method="afterLog" pointcut-ref="pc_log"/>
<!-- 返回通知 -->
<aop:after-returning method="returningLog"  pointcut-ref="pc_log" returning="rtn"/>
<!-- 异常通知 -->
<aop:after-throwing method="errorLog" pointcut-ref="pc_log" throwing="msg" />
<!-- 环绕通知 -->
<aop:around method="aroundLog" pointcut-ref="pc_log" />

</aop:aspect>

<aop:aspect ref="check">
<aop:before method="beforeCheck" pointcut-ref="pc_log"  />

</aop:aspect>

</aop:config>
</beans>
原文地址:https://www.cnblogs.com/zs6666/p/6181537.html