我正在尝试将事务与 MyBatis 和 Spring 一起使用,并且想知道是否有最佳实践来实现这一目标?任何提示或想法表示赞赏。
我的应用程序将在针对 MySQL 数据库的 tomcat 容器中运行。
我正在尝试将事务与 MyBatis 和 Spring 一起使用,并且想知道是否有最佳实践来实现这一目标?任何提示或想法表示赞赏。
我的应用程序将在针对 MySQL 数据库的 tomcat 容器中运行。
您想查看@Transactional 注释文档 就最佳实践而言,它是数据库事务和spring 的混合体。看看哪里需要回滚数据,是否需要 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>