2011/03/31

[Java] SpringFrameworkのトランザクション管理について

概要

SpringFrameworkのトランザクション管理の方法について説明します。

動作環境

項目内容
OSMac OS X 10.06
DBMySQL 5.5
開発環境eclipse3.6
SpringFramework1.2
iBatis2.0

前提事項

・特になし

内容

Springでは、トランザクション管理に以下のクラスを使用するようです。
org.springframework.transaction.interceptor.TransactionProxyFactoryBean

こちらをapplicationContext.xmlに定義します。
こんな感じで実装しました。
  1. <bean id="transactionProxyFactoryBean" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">  
  2.     <property name="transactionManager">  
  3.       <ref local="transactionManager">  
  4.     </ref></property>  
  5.     <property name="target">  
  6.       <bean class="{完全クラス名}">  
  7.     </bean></property>  
  8.     <property name="transactionAttributes">  
  9.       <props>  
  10.         <prop key="*">PROPAGATION_REQUIRED</prop>  
  11.       </props>  
  12.     </property>  
  13. </bean>  

重要なのは、上記の「transactionAttributes」です。
prop keyで指定するメソッドにて、トランザクションの状態を定義するようです。
この例だと、すべてのメソッドを同じようにトランザクション管理するという内容になります。

テスト

なし

参考情報


最後に

次回以降は、Swing+SpringFramework+iBatisを組み合わせたアプリケーションを作成します。

0 件のコメント:

コメントを投稿