mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Polish "Ensure that Flyway/Liquibase run before jOOQ's DSLContext is used"
See gh-25279
This commit is contained in:
parent
c55200d19a
commit
78941c32c4
@ -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)
|
||||
|
@ -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() {
|
||||
|
@ -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) -> {
|
||||
|
Loading…
Reference in New Issue
Block a user