首页 > 编程语言 > 详细

Spring中AOP(通知)的使用

时间:2016-12-15 00:24:55      阅读:226      评论:0      收藏:0      [点我收藏+]

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>

 

Spring中AOP(通知)的使用

原文:http://www.cnblogs.com/zs6666/p/6181537.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!