四、用事務通知聲明式地管理事務

一、用事務通知聲明式地管理事務

spring 2.x 提供了一個事務通知,你能用tx Schema中定義的<tx:advice>元素輕鬆的對它進行配置。

 

<bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 以AspectJ方式 定義 AOP -->
<aop:config>
<aop:pointcut id="yyManagerOperations" expression="execution(* com.xx.yy..*Manager.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="yyManagerOperations" />
</aop:config>
<!-- 相當於創建了一個 TransactionIntercepter 事務環繞通知 -->

<!-- 基本事務定義,使用transactionManager作事務管理,默認get*方法的事務爲readonly,其餘方法按默認設置.
默認的設置請參考Spring文檔事務一章. -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true"
propagation="REQUIRED" />
<tx:method name="find*" read-only="true"
propagation="REQUIRED" />
<tx:method name="query*" read-only="true"
propagation="REQUIRED" />
<tx:method name="show*" read-only="true"
propagation="REQUIRED" />
<tx:method name="list*" read-only="true"
propagation="REQUIRED" />
<tx:method name="*" propagation="REQUIRED"
rollback-for="com.xx.core.exception.BusinessException" />
</tx:attributes>
</tx:advice>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章