0

MyBatis と Spring でトランザクションを使用しようとしていますが、これを達成するためのベスト プラクティスがあるかどうか疑問に思っていましたか? ヒントや考えをいただければ幸いです。

私のアプリケーションは、MySQL データベースに対して tomcat コンテナーで実行されます。

4

1 に答える 1

1

@Transactional アノテーションドキュメントを参照してください 。ベスト プラクティスに関しては、データベース トランザクションとスプリングが混在しています。データをロールバックする必要がある場所、JTA が必要かなどを確認します。

クラス例

@Transactional
public class DefaultFooService implements FooService {

   Foo getFoo(String fooName);
}

XML の例

<!-- this is the service object that we want to make transactional -->
<bean id="fooService" class="x.y.service.DefaultFooService"/>
<!-- enable the configuration of transactional behavior based on annotations -->         <tx:annotation-driven transaction-manager="txManager"/>

<!-- a PlatformTransactionManager is still required -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- (this dependency is defined somewhere else) -->
    <property name="dataSource" ref="dataSource"/>
</bean>
于 2011-08-23T22:48:11.123 に答える