From f9d50ee86a48026c6dee1a77f1de0deeadcb238a Mon Sep 17 00:00:00 2001 From: Marten Deinum Date: Fri, 2 Oct 2020 10:12:41 +0200 Subject: [PATCH] Prefer JdbcTransactionManager over DataSourceTransactionManager Spring 5.3 introduced the JdbcTransactionManager with exception translation on commit and rollback. This commit updates the auto-configuration to use this implementation rather than DataSourceTransactionManager. See gh-23672 --- .../DataSourceTransactionManagerAutoConfiguration.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfiguration.java index 63a3c598f6..8acc90e425 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfiguration.java @@ -30,12 +30,11 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.support.JdbcTransactionManager; import org.springframework.transaction.TransactionManager; /** - * {@link EnableAutoConfiguration Auto-configuration} for - * {@link DataSourceTransactionManager}. + * {@link EnableAutoConfiguration Auto-configuration} for {@link JdbcTransactionManager}. * * @author Dave Syer * @author Stephane Nicoll @@ -55,9 +54,9 @@ public class DataSourceTransactionManagerAutoConfiguration { @Bean @ConditionalOnMissingBean(TransactionManager.class) - DataSourceTransactionManager transactionManager(DataSource dataSource, + JdbcTransactionManager transactionManager(DataSource dataSource, ObjectProvider transactionManagerCustomizers) { - DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource); + JdbcTransactionManager transactionManager = new JdbcTransactionManager(dataSource); transactionManagerCustomizers.ifAvailable((customizers) -> customizers.customize(transactionManager)); return transactionManager; }