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>

相關文章
相關標籤/搜索