From c55200d19a4a49ba112e743f19861ea1c308d6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Sun, 14 Feb 2021 21:44:35 -0600 Subject: [PATCH 1/2] Ensure that Flyway/Liquibase run before jOOQ's DSLContext is used See gh-25279 --- .../flyway/FlywayAutoConfiguration.java | 38 +++++++++++- .../DslContextDependsOnPostProcessor.java | 53 ++++++++++++++++ .../liquibase/LiquibaseAutoConfiguration.java | 22 ++++++- .../flyway/FlywayAutoConfigurationTests.java | 61 ++++++++++++++++++- .../LiquibaseAutoConfigurationTests.java | 13 +++- 5 files changed, 180 insertions(+), 7 deletions(-) create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/DslContextDependsOnPostProcessor.java diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java index 1ca4fd424d..4ede9f50a3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -33,6 +33,7 @@ import org.flywaydb.core.api.MigrationVersion; import org.flywaydb.core.api.callback.Callback; import org.flywaydb.core.api.configuration.FluentConfiguration; import org.flywaydb.core.api.migration.JavaMigration; +import org.jooq.DSLContext; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -44,6 +45,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.data.jpa.EntityManagerFactoryDependsOnPostProcessor; import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration.FlywayDataSourceCondition; +import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration.FlywayDslContextDependsOnPostProcessor; import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration.FlywayEntityManagerFactoryDependsOnPostProcessor; import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration.FlywayJdbcOperationsDependsOnPostProcessor; import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration.FlywayNamedParameterJdbcOperationsDependencyConfiguration; @@ -52,6 +54,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.autoconfigure.jdbc.JdbcOperationsDependsOnPostProcessor; import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.NamedParameterJdbcOperationsDependsOnPostProcessor; +import org.springframework.boot.autoconfigure.jooq.DslContextDependsOnPostProcessor; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -96,7 +99,7 @@ import org.springframework.util.StringUtils; @AutoConfigureAfter({ DataSourceAutoConfiguration.class, JdbcTemplateAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) @Import({ FlywayEntityManagerFactoryDependsOnPostProcessor.class, FlywayJdbcOperationsDependsOnPostProcessor.class, - FlywayNamedParameterJdbcOperationsDependencyConfiguration.class }) + FlywayNamedParameterJdbcOperationsDependencyConfiguration.class, FlywayDslContextDependsOnPostProcessor.class }) public class FlywayAutoConfiguration { @Bean @@ -115,7 +118,8 @@ public class FlywayAutoConfiguration { @EnableConfigurationProperties({ DataSourceProperties.class, FlywayProperties.class }) @Import({ FlywayMigrationInitializerEntityManagerFactoryDependsOnPostProcessor.class, FlywayMigrationInitializerJdbcOperationsDependsOnPostProcessor.class, - FlywayMigrationInitializerNamedParameterJdbcOperationsDependsOnPostProcessor.class }) + FlywayMigrationInitializerNamedParameterJdbcOperationsDependsOnPostProcessor.class, + FlywayMigrationInitializerDslContextDependsOnPostProcessor.class }) public static class FlywayConfiguration { @Bean @@ -326,6 +330,20 @@ public class FlywayAutoConfiguration { } + /** + * Post processor to ensure that {@link DSLContext} beans depend on any + * {@link FlywayMigrationInitializer} beans. + */ + @ConditionalOnClass(DSLContext.class) + @ConditionalOnBean(DSLContext.class) + static class FlywayMigrationInitializerDslContextDependsOnPostProcessor extends DslContextDependsOnPostProcessor { + + FlywayMigrationInitializerDslContextDependsOnPostProcessor() { + super(FlywayMigrationInitializer.class); + } + + } + /** * Post processor to ensure that {@link EntityManagerFactory} beans depend on any * {@link Flyway} beans. @@ -369,6 +387,20 @@ public class FlywayAutoConfiguration { } + /** + * Post processor to ensure that {@link DSLContext} beans depend on any {@link Flyway} + * beans. + */ + @ConditionalOnClass(DSLContext.class) + @ConditionalOnBean(DSLContext.class) + protected static class FlywayDslContextDependsOnPostProcessor extends DslContextDependsOnPostProcessor { + + public FlywayDslContextDependsOnPostProcessor() { + super(Flyway.class); + } + + } + private static class LocationResolver { private static final String VENDOR_PLACEHOLDER = "{vendor}"; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/DslContextDependsOnPostProcessor.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/DslContextDependsOnPostProcessor.java new file mode 100644 index 0000000000..d951fba610 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/DslContextDependsOnPostProcessor.java @@ -0,0 +1,53 @@ +/* + * Copyright 2012-2021 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.jooq; + +import org.jooq.DSLContext; + +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; +import org.springframework.boot.autoconfigure.AbstractDependsOnBeanFactoryPostProcessor; + +/** + * {@link BeanFactoryPostProcessor} that can be used to dynamically declare that all + * {@link DSLContext} beans should "depend on" one or more specific beans. + * + * @author EddĂș MelĂ©ndez + * @since 2.3.9 + * @see BeanDefinition#setDependsOn(String[]) + */ +public class DslContextDependsOnPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor { + + /** + * Creates a new {@code DslContextDependsOnPostProcessor} that will set up + * dependencies upon beans with the given names. + * @param dependsOn names of the beans to depend upon + */ + public DslContextDependsOnPostProcessor(String... dependsOn) { + super(DSLContext.class, dependsOn); + } + + /** + * Creates a new {@code DslContextDependsOnPostProcessor} that will set up + * dependencies upon beans with the given types. + * @param dependsOn types of the beans to depend upon + */ + public DslContextDependsOnPostProcessor(Class... dependsOn) { + super(DSLContext.class, dependsOn); + } + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java index 6044215653..9c70170b73 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -23,6 +23,7 @@ import javax.sql.DataSource; import liquibase.change.DatabaseChange; import liquibase.integration.spring.SpringLiquibase; +import org.jooq.DSLContext; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -37,7 +38,9 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.autoconfigure.jdbc.JdbcOperationsDependsOnPostProcessor; import org.springframework.boot.autoconfigure.jdbc.NamedParameterJdbcOperationsDependsOnPostProcessor; +import org.springframework.boot.autoconfigure.jooq.DslContextDependsOnPostProcessor; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration.LiquibaseDataSourceCondition; +import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration.LiquibaseDslContextDependsOnPostProcessor; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration.LiquibaseEntityManagerFactoryDependsOnPostProcessor; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration.LiquibaseJdbcOperationsDependsOnPostProcessor; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration.LiquibaseNamedParameterJdbcOperationsDependsOnPostProcessor; @@ -75,7 +78,8 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; @AutoConfigureAfter({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) @Import({ LiquibaseEntityManagerFactoryDependsOnPostProcessor.class, LiquibaseJdbcOperationsDependsOnPostProcessor.class, - LiquibaseNamedParameterJdbcOperationsDependsOnPostProcessor.class }) + LiquibaseNamedParameterJdbcOperationsDependsOnPostProcessor.class, + LiquibaseDslContextDependsOnPostProcessor.class }) public class LiquibaseAutoConfiguration { @Bean @@ -206,6 +210,20 @@ public class LiquibaseAutoConfiguration { } + /** + * Post processor to ensure that {@link DSLContext} beans depend on the liquibase + * bean. + */ + @ConditionalOnClass(DSLContext.class) + @ConditionalOnBean(DSLContext.class) + static class LiquibaseDslContextDependsOnPostProcessor extends DslContextDependsOnPostProcessor { + + LiquibaseDslContextDependsOnPostProcessor() { + super(SpringLiquibase.class); + } + + } + static final class LiquibaseDataSourceCondition extends AnyNestedCondition { LiquibaseDataSourceCondition() { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java index f978ed9b0e..ebe496c6ab 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -32,11 +32,15 @@ import org.flywaydb.core.api.callback.Event; import org.flywaydb.core.api.migration.JavaMigration; import org.flywaydb.core.internal.license.FlywayProUpgradeRequiredException; import org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform; +import org.jooq.DSLContext; +import org.jooq.SQLDialect; +import org.jooq.impl.DefaultDSLContext; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InOrder; import org.springframework.beans.factory.BeanCreationException; +import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.jdbc.DataSourceBuilder; @@ -520,6 +524,25 @@ class FlywayAutoConfigurationTests { }); } + @Test + void userConfigurationDslContextDependency() { + this.contextRunner + .withUserConfiguration(EmbeddedDataSourceConfiguration.class, CustomFlywayWithJooqConfiguration.class) + .run((context) -> { + BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("dslContext"); + assertThat(beanDefinition.getDependsOn()).containsExactly("flyway"); + }); + } + + @Test + void userConfigurationWithFlywayMigrationAndDslContextDependency() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class, + CustomFlywayMigrationInitializerWithJooqConfiguration.class).run((context) -> { + BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("dslContext"); + assertThat(beanDefinition.getDependsOn()).containsExactly("flywayMigrationInitializer", "flyway"); + }); + } + @Configuration(proxyBeanMethods = false) static class FlywayDataSourceConfiguration { @@ -748,6 +771,42 @@ class FlywayAutoConfigurationTests { } + @Configuration + static class CustomFlywayWithJooqConfiguration { + + @Bean + Flyway flyway(DataSource dataSource) { + return Flyway.configure().dataSource(dataSource).load(); + } + + @Bean + DSLContext dslContext() { + return new DefaultDSLContext(SQLDialect.H2); + } + + } + + @Configuration + protected static class CustomFlywayMigrationInitializerWithJooqConfiguration { + + private final DataSource dataSource; + + protected CustomFlywayMigrationInitializerWithJooqConfiguration(DataSource dataSource) { + this.dataSource = dataSource; + } + + @Bean + public FlywayMigrationInitializer flywayMigrationInitializer(Flyway flyway) { + return new FlywayMigrationInitializer(flyway); + } + + @Bean + DSLContext dslContext() { + return new DefaultDSLContext(SQLDialect.H2); + } + + } + static final class CustomClassLoader extends ClassLoader { private CustomClassLoader(ClassLoader parent) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java index 7f854d2c52..6ea18343e7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -41,6 +41,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration; +import org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.context.event.ApplicationStartingEvent; import org.springframework.boot.jdbc.DataSourceBuilder; @@ -374,6 +375,16 @@ class LiquibaseAutoConfigurationTests { .run(assertLiquibase((liquibase) -> assertThat(liquibase.getTag()).isEqualTo("1.0.0"))); } + @Test + void userConfigurationDslContextDependency() { + this.contextRunner.withConfiguration(AutoConfigurations.of(JooqAutoConfiguration.class)) + .withUserConfiguration(LiquibaseUserConfiguration.class, EmbeddedDataSourceConfiguration.class) + .run((context) -> { + BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("dslContext"); + assertThat(beanDefinition.getDependsOn()).containsExactly("springLiquibase"); + }); + } + private ContextConsumer assertLiquibase(Consumer consumer) { return (context) -> { assertThat(context).hasSingleBean(SpringLiquibase.class); From 78941c32c48d671aa53a0739f64c4aa80487eac7 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 16 Feb 2021 12:04:59 +0000 Subject: [PATCH 2/2] Polish "Ensure that Flyway/Liquibase run before jOOQ's DSLContext is used" See gh-25279 --- .../liquibase/LiquibaseAutoConfiguration.java | 14 ++--- .../flyway/FlywayAutoConfigurationTests.java | 62 ++++++++----------- .../LiquibaseAutoConfigurationTests.java | 11 +++- 3 files changed, 44 insertions(+), 43 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java index 9c70170b73..ffc24fbc8d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java @@ -167,8 +167,8 @@ public class LiquibaseAutoConfiguration { } /** - * Post processor to ensure that {@link EntityManagerFactory} beans depend on the - * liquibase bean. + * Post processor to ensure that {@link EntityManagerFactory} beans depend on any + * {@link SpringLiquibase} beans. */ @ConditionalOnClass(LocalContainerEntityManagerFactoryBean.class) @ConditionalOnBean(AbstractEntityManagerFactoryBean.class) @@ -182,8 +182,8 @@ public class LiquibaseAutoConfiguration { } /** - * Additional configuration to ensure that {@link JdbcOperations} beans depend on the - * liquibase bean. + * Additional configuration to ensure that {@link JdbcOperations} beans depend on any + * {@link SpringLiquibase} beans. */ @ConditionalOnClass(JdbcOperations.class) @ConditionalOnBean(JdbcOperations.class) @@ -197,7 +197,7 @@ public class LiquibaseAutoConfiguration { /** * Post processor to ensure that {@link NamedParameterJdbcOperations} beans depend on - * the liquibase bean. + * any {@link SpringLiquibase} beans. */ @ConditionalOnClass(NamedParameterJdbcOperations.class) @ConditionalOnBean(NamedParameterJdbcOperations.class) @@ -211,8 +211,8 @@ public class LiquibaseAutoConfiguration { } /** - * Post processor to ensure that {@link DSLContext} beans depend on the liquibase - * bean. + * Post processor to ensure that {@link DSLContext} beans depend on any + * {@link SpringLiquibase} beans. */ @ConditionalOnClass(DSLContext.class) @ConditionalOnBean(DSLContext.class) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java index ebe496c6ab..0f4239dc4c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java @@ -525,24 +525,32 @@ class FlywayAutoConfigurationTests { } @Test - void userConfigurationDslContextDependency() { - this.contextRunner - .withUserConfiguration(EmbeddedDataSourceConfiguration.class, CustomFlywayWithJooqConfiguration.class) + void whenFlywayIsAutoConfiguredThenJooqDslContextDependsOnFlywayBeans() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class, JooqConfiguration.class) .run((context) -> { BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("dslContext"); - assertThat(beanDefinition.getDependsOn()).containsExactly("flyway"); + assertThat(beanDefinition.getDependsOn()).containsExactly("flywayInitializer", "flyway"); }); } @Test - void userConfigurationWithFlywayMigrationAndDslContextDependency() { - this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class, - CustomFlywayMigrationInitializerWithJooqConfiguration.class).run((context) -> { + void whenCustomMigrationInitializerIsDefinedThenJooqDslContextDependsOnIt() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class, JooqConfiguration.class, + CustomFlywayMigrationInitializer.class).run((context) -> { BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("dslContext"); assertThat(beanDefinition.getDependsOn()).containsExactly("flywayMigrationInitializer", "flyway"); }); } + @Test + void whenCustomFlywayIsDefinedThenJooqDslContextDependsOnIt() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class, JooqConfiguration.class, + CustomFlyway.class).run((context) -> { + BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("dslContext"); + assertThat(beanDefinition.getDependsOn()).containsExactly("customFlyway"); + }); + } + @Configuration(proxyBeanMethods = false) static class FlywayDataSourceConfiguration { @@ -619,6 +627,16 @@ class FlywayAutoConfigurationTests { } + @Configuration(proxyBeanMethods = false) + static class CustomFlyway { + + @Bean + Flyway customFlyway() { + return Flyway.configure().load(); + } + + } + @Configuration(proxyBeanMethods = false) static class CustomFlywayMigrationInitializerWithJpaConfiguration { @@ -771,34 +789,8 @@ class FlywayAutoConfigurationTests { } - @Configuration - static class CustomFlywayWithJooqConfiguration { - - @Bean - Flyway flyway(DataSource dataSource) { - return Flyway.configure().dataSource(dataSource).load(); - } - - @Bean - DSLContext dslContext() { - return new DefaultDSLContext(SQLDialect.H2); - } - - } - - @Configuration - protected static class CustomFlywayMigrationInitializerWithJooqConfiguration { - - private final DataSource dataSource; - - protected CustomFlywayMigrationInitializerWithJooqConfiguration(DataSource dataSource) { - this.dataSource = dataSource; - } - - @Bean - public FlywayMigrationInitializer flywayMigrationInitializer(Flyway flyway) { - return new FlywayMigrationInitializer(flyway); - } + @Configuration(proxyBeanMethods = false) + static class JooqConfiguration { @Bean DSLContext dslContext() { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java index 6ea18343e7..c7b77c6f5b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java @@ -376,7 +376,16 @@ class LiquibaseAutoConfigurationTests { } @Test - void userConfigurationDslContextDependency() { + void whenLiquibaseIsAutoConfiguredThenJooqDslContextDependsOnSpringLiquibaseBeans() { + this.contextRunner.withConfiguration(AutoConfigurations.of(JooqAutoConfiguration.class)) + .withUserConfiguration(EmbeddedDataSourceConfiguration.class).run((context) -> { + BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("dslContext"); + assertThat(beanDefinition.getDependsOn()).containsExactly("liquibase"); + }); + } + + @Test + void whenCustomSpringLiquibaseIsDefinedThenJooqDslContextDependsOnSpringLiquibaseBeans() { this.contextRunner.withConfiguration(AutoConfigurations.of(JooqAutoConfiguration.class)) .withUserConfiguration(LiquibaseUserConfiguration.class, EmbeddedDataSourceConfiguration.class) .run((context) -> {