From 56a1551c2de47350c3baada441f6e9b467c64668 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 1 Feb 2023 14:54:36 +0000 Subject: [PATCH] Polish "Configure jOOQ with TransactionProvider bean when available" See gh-33979 --- .../jooq/JooqAutoConfigurationTests.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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 a85621810459..6d608d69af6e 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 @@ -175,6 +175,19 @@ void transactionProviderBacksOffOnExistingTransactionProvider() { .run((context) -> { TransactionProvider transactionProvider = context.getBean(TransactionProvider.class); assertThat(transactionProvider).isInstanceOf(CustomTransactionProvider.class); + DSLContext dsl = context.getBean(DSLContext.class); + assertThat(dsl.configuration().transactionProvider()).isSameAs(transactionProvider); + }); + } + + @Test + void transactionProviderFromConfigurationCustomizerOverridesTransactionProviderBean() { + this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class, TxManagerConfiguration.class, + CustomTransactionProviderFromCustomizerConfiguration.class).run((context) -> { + TransactionProvider transactionProvider = context.getBean(TransactionProvider.class); + assertThat(transactionProvider).isInstanceOf(SpringTransactionProvider.class); + DSLContext dsl = context.getBean(DSLContext.class); + assertThat(dsl.configuration().transactionProvider()).isInstanceOf(CustomTransactionProvider.class); }); } @@ -239,6 +252,16 @@ TransactionProvider transactionProvider() { } + @Configuration(proxyBeanMethods = false) + static class CustomTransactionProviderFromCustomizerConfiguration { + + @Bean + DefaultConfigurationCustomizer transactionProviderCustomizer() { + return (configuration) -> configuration.setTransactionProvider(new CustomTransactionProvider()); + } + + } + @Configuration(proxyBeanMethods = false) static class TxManagerConfiguration {