SpringMVC+Mybatis声明式事务分析

(2-1): expression="execution(* *..*SVImpl.*(..))" 的使用

第一个【*】: 任意返回值类型

第二个【*】:任意包名

第一个【..】:通配包路径 可以有0个或者多个包路径

第三个【*】:任意字符+SVImpl的class

第四个【*】:任意方法名

第二个【..】:通配方法可以有0个或者多个参数

(2-2): 事务的传播级别

1、PROPAGATION_REQUIRED:如果存在一个事务,则支持当前事务。如果没有事务则开启。

2、PROPAGATION_SUPPORTS : 如果存在一个事务,支持当前事务。如果没有事务,则非事务的执行。 
3、PROPAGATION_MANDATORY : 如果已经存在一个事务,支持当前事务。如果没有一个活动的事务,则抛出异常。 
4、PROPAGATION_REQUIRES_NEW : 总是开启一个新的事务。如果一个事务存在,则将这个存在的事务挂起。 
5、PROPAGATION_NOT_SUPPORTED : 总是非事务地执行,并挂起任何存在的事务。 
6、PROPAGATION_NEVER : 总是非事务地执行,如果存在一个活动事务,则抛出异常。 
7、 PROPAGATION_NESTED : 如果一个活动的事务存在,则运行在一个嵌套的事务中,如果没有活动事务,则按TransactionDefinition.PROPAGATION_REQUIRED属性执行

 <!-- 拦截器方式配置事务 -->

 <!-- 配置事务传播级别 -->

 <tx:advice id="txAdvice" transaction-manager="transactionManager">

  <tx:attributes>

   <tx:method name="save*" propagation="REQUIRED" />

   <tx:method name="add*" propagation="REQUIRED" />

   <tx:method name="create*" propagation="REQUIRED" />

   <tx:method name="insert*" propagation="REQUIRED" />

   <tx:method name="update*" propagation="REQUIRED" />

   <tx:method name="merge*" propagation="REQUIRED" />

   <tx:method name="del*" propagation="REQUIRED" />

   <tx:method name="remove*" propagation="REQUIRED" />

   <tx:method name="put*" propagation="REQUIRED" />

   <tx:method name="get*" propagation="SUPPORTS" read-only="true" />

   <tx:method name="count*" propagation="SUPPORTS" read-only="true" />

   <tx:method name="find*" propagation="SUPPORTS" read-only="true" />

   <tx:method name="list*" propagation="SUPPORTS" read-only="true" />

   <tx:method name="*" propagation="SUPPORTS" read-only="true" />

  </tx:attributes>

 </tx:advice>  

 <aop:config>

  <!-- 只对业务逻辑层实施事务 -->

  <aop:pointcut id="txPointcut"

   expression="execution(* *..*SVImpl.*(..))" />

   

  <!-- Advisor定义,切入点和通知分别为txPointcut、txAdvice -->

  <aop:advisor pointcut-ref="txPointcut" advice-ref="txAdvice" />

 </aop:config>


转载于:https://my.oschina.net/u/2291124/blog/660730

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值