From 1606f5b88c2c960a6e38f04760c56b7538314d5a Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Thu, 12 Jan 2023 11:24:49 +0100 Subject: [PATCH] Back off Jooq's TransactionProvider on custom TransactionProvider Closes gh-32899 --- .../jooq/JooqAutoConfiguration.java | 1 + .../jooq/JooqAutoConfigurationTests.java | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java index e9108b4c21..0b98153b7c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java @@ -71,6 +71,7 @@ public class JooqAutoConfiguration { @Bean @ConditionalOnBean(PlatformTransactionManager.class) + @ConditionalOnMissingBean(TransactionProvider.class) public SpringTransactionProvider transactionProvider(PlatformTransactionManager txManager) { return new SpringTransactionProvider(txManager); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java index 938327660e..d13daf5b5b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java @@ -29,7 +29,9 @@ import org.jooq.RecordListenerProvider; import org.jooq.RecordMapperProvider; import org.jooq.RecordUnmapperProvider; import org.jooq.SQLDialect; +import org.jooq.TransactionContext; import org.jooq.TransactionListenerProvider; +import org.jooq.TransactionProvider; import org.jooq.TransactionalRunnable; import org.jooq.VisitListenerProvider; import org.jooq.impl.DataSourceConnectionProvider; @@ -188,6 +190,16 @@ class JooqAutoConfigurationTests { .isEqualTo(SQLDialect.POSTGRES)); } + @Test + void transactionProviderBacksOffOnExistingTransactionProvider() { + this.contextRunner + .withUserConfiguration(JooqDataSourceConfiguration.class, CustomTransactionProviderConfiguration.class) + .run((context) -> { + TransactionProvider transactionProvider = context.getBean(TransactionProvider.class); + assertThat(transactionProvider).isInstanceOf(CustomTransactionProvider.class); + }); + } + static class AssertFetch implements TransactionalRunnable { private final DSLContext dsl; @@ -239,6 +251,16 @@ class JooqAutoConfigurationTests { } + @Configuration(proxyBeanMethods = false) + static class CustomTransactionProviderConfiguration { + + @Bean + TransactionProvider transactionProvider() { + return new CustomTransactionProvider(); + } + + } + @Configuration(proxyBeanMethods = false) static class TxManagerConfiguration { @@ -259,4 +281,23 @@ class JooqAutoConfigurationTests { } + static class CustomTransactionProvider implements TransactionProvider { + + @Override + public void begin(TransactionContext ctx) { + + } + + @Override + public void commit(TransactionContext ctx) { + + } + + @Override + public void rollback(TransactionContext ctx) { + + } + + } + }