在Spring Batch中使用2个数据源时面临的提交问题

时间:2019-06-08 22:21:29

标签: spring-boot spring-batch

我的项目进行批处理,并尝试使用2个数据源(oracle)(一个用于spring元数据,另一个用于应用程序)。

该示例配置位于github项目(github.com/jobas2007/spring_proj)中,但是由于配置了2个事务管理器/数据源,因此在为2个数据源完成的提交中管理事务似乎不一致。主要数据源(用于批处理)的提交正确进行,但是最终在ItemWriter中执行“保存”时,在保存/更新到应用程序表的过程中观察到非常不可预知的行为。

请提供一种管理多个数据源之间事务的好方法吗?

根据链接https://blog.codecentric.de/en/2012/03/transactions-in-spring-batch-part-1-the-basics/,进入步骤时Tx从大块开始

曾尝试过其中一篇建议使用“ ChainedTransactionManager”,但在接线时面临重大问题 Use of multiple DataSources in Spring Batch

代码在github

预期结果是具有可预测的强大的TX管理

1 个答案:

答案 0 :(得分:0)

如果您决定在Spring Batch中使用两个数据源,则需要使用JtaTransactionManager在两个数据源之间同步distributed transaction

您可以在此处找到David Syer博士撰写的精彩文章:Distributed transactions in Spring, with and without XA

相关问题