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 f39bd6f4c4..e955e634b5 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 @@ -21,6 +21,7 @@ import javax.sql.DataSource; import org.jooq.ConnectionProvider; import org.jooq.DSLContext; import org.jooq.ExecuteListenerProvider; +import org.jooq.TransactionProvider; import org.jooq.impl.DataSourceConnectionProvider; import org.jooq.impl.DefaultConfiguration; import org.jooq.impl.DefaultDSLContext; @@ -62,6 +63,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 f0e845c89f..c2b722ec9a 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 @@ -25,6 +25,8 @@ import org.jooq.DSLContext; import org.jooq.ExecuteListener; import org.jooq.ExecuteListenerProvider; import org.jooq.SQLDialect; +import org.jooq.TransactionContext; +import org.jooq.TransactionProvider; import org.jooq.TransactionalRunnable; import org.jooq.impl.DataSourceConnectionProvider; import org.jooq.impl.DefaultExecuteListenerProvider; @@ -155,6 +157,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; @@ -206,6 +218,16 @@ class JooqAutoConfigurationTests { } + @Configuration(proxyBeanMethods = false) + static class CustomTransactionProviderConfiguration { + + @Bean + TransactionProvider transactionProvider() { + return new CustomTransactionProvider(); + } + + } + @Configuration(proxyBeanMethods = false) static class TxManagerConfiguration { @@ -226,4 +248,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) { + + } + + } + }