你的位置:首页 > 软件开发 > Java > Spring 一二事(9)

Spring 一二事(9)

发布时间:2016-03-22 14:00:08
AOP在spring中是非常重要的一个在切面类中,有5种通知类型:aop:before 前置通知aop:after-returning 后置通知aop:after 最终通知aop:after-throwing 异常通知aop:around 环绕通知 ...

AOP在spring中是非常重要的一个

在切面类中,有5种通知类型:

aop:before  前置通知

aop:after-returning  后置通知

aop:after  最终通知

aop:after-throwing  异常通知

aop:around  环绕通知

 1    <bean id="personDAO" class="com.lee.spring002.aop.></bean> 2   <bean id="transaction" class="com.lee.spring002.aop.></bean> 3    4   <aop:config > 5     <!-- 切入点表达式,作用:确定目标类 --> 6     <!-- spring 会自动检测这个表达式下的类是否是切面,如果是,则不会包含进来 --> 7     <aop:pointcut expression="execution(* com.lee.spring002.aop. id="perform"/> 8     <!-- ref 指向切面 --> 9     <aop:aspect ref="transaction">10       <!-- 前置通知 -->11       <aop:before method="beginTransaction" pointcut-ref="perform"/>12       13       <!-- 14         后置通知15           可以获取目标方法的返回值(前置方法获取不到)16           如果目标方法抛出异常,后置通知则不会继续执行17       -->18       <aop:after-returning method="commit" pointcut-ref="perform" returning="val"/>19       20       <!-- 21         最终通知22           无论目标方法是否抛出异常都将执行此方法23       -->24       <aop:after method="finallyDisplay" pointcut-ref="perform"/>25       26       <!-- 27          异常通知28        -->29        <aop:after-throwing method="exception" pointcut-ref="perform" throwing="content"/>30        31        <!-- 32          环绕通知33            能控制目标方法能否执行34            前置通知和后置通知能在目标方法的前后加代码,但是不能控制方法的执行35        -->36        <aop:around method="arround" pointcut-ref="perform"/>37     </aop:aspect>38   </aop:config>

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:Spring 一二事(9)

关键词:Spring

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录