Spring Batch Composite Item Writer Transaction Management

622 views Asked by At

Regarding the post How does Spring Batch CompositeItemWriter manage transaction for delegate writers? , for composite item writer transaction management, shouldn't we wrap the data source in a transaction manager like below ? Without the below bean definition the transaction management is not working with Oracle and Hikari CP. Not sure how the provided example in the post is working..please clarify

@Bean
public PlatformTransactionManager transactionManager(DataSource dataSource) {
            return new DataSourceTransactionManager(dataSource);
}
1

There are 1 answers

3
Mahmoud Ben Hassine On BEST ANSWER

There is no need to add that bean, the example provides a DataSource and uses @EnableBatchProcessing, so Spring Batch will configure a DataSourceTransactionManager by default. This is explained in the documentation of @EnableBatchProcessing.