SpringMVC+Mybatis声明式事务分析

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

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

第二个【*】:任意包名orm

第一个【..】:通配包路径 能够有0个或者多个包路径事务

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

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

第二个【..】:通配方法能够有0个或者多个参数it

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

一、PROPAGATION_REQUIRED:若是存在一个事务,则支持当前事务。若是没有事务则开启。class

二、PROPAGATION_SUPPORTS : 若是存在一个事务,支持当前事务。若是没有事务,则非事务的执行。 
三、PROPAGATION_MANDATORY : 若是已经存在一个事务,支持当前事务。若是没有一个活动的事务,则抛出异常。 
四、PROPAGATION_REQUIRES_NEW : 老是开启一个新的事务。若是一个事务存在,则将这个存在的事务挂起。 
五、PROPAGATION_NOT_SUPPORTED : 老是非事务地执行,并挂起任何存在的事务。 
六、PROPAGATION_NEVER : 老是非事务地执行,若是存在一个活动事务,则抛出异常。 
七、 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>

相关文章
相关标签/搜索