Change transaction manager type in default batch configuration
This commits changes the type of the transaction manager from `DataSourceTransactionManager` to `JdbcTransactionManager` in the default configuration of `@EnableBatchProcessing`. The `JdbcTransactionManager` adds common JDBC exception translation which is beneficial for Spring Batch to improve exception handling and error reporting. Resolves #4126
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2021 the original author or authors.
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,7 +37,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.jdbc.support.JdbcTransactionManager;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -124,8 +124,7 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean {
|
||||
if (scriptResource == null || !scriptResource.exists()) {
|
||||
return;
|
||||
}
|
||||
TransactionTemplate transactionTemplate = new TransactionTemplate(
|
||||
new DataSourceTransactionManager(this.dataSource));
|
||||
TransactionTemplate transactionTemplate = new TransactionTemplate(new JdbcTransactionManager(this.dataSource));
|
||||
transactionTemplate.execute((TransactionCallback<Void>) status -> {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource);
|
||||
String[] scripts;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
</bean>
|
||||
|
||||
<bean id="transactionManager"
|
||||
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
|
||||
class="org.springframework.jdbc.support.JdbcTransactionManager"
|
||||
lazy-init="true">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<jdbc:script location="classpath:/org/springframework/batch/core/schema-hsqldb.sql"/>
|
||||
</jdbc:initialize-database>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<bean id="transactionManager" class="org.springframework.jdbc.support.JdbcTransactionManager">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user