From bacd36f0cfc9fd3ed7da2e8fd2dbc3da924fe2a5 Mon Sep 17 00:00:00 2001 From: Dmytro Nosan Date: Mon, 21 Oct 2019 14:29:47 +0300 Subject: [PATCH 1/2] Apply dependsOn semantic between Liquibase and JPA This commits restores the dependency between Liquibase and the JPA EntityManager even if a custom `SpringLiquibase` is configured. See gh-18673 --- .../liquibase/LiquibaseAutoConfiguration.java | 5 +++-- .../liquibase/LiquibaseAutoConfigurationTests.java | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 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 9e9b766ecb..ba51aadb80 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 @@ -38,6 +38,7 @@ 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.liquibase.LiquibaseAutoConfiguration.LiquibaseDataSourceCondition; +import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration.LiquibaseEntityManagerFactoryDependsOnPostProcessor; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration.LiquibaseJdbcOperationsDependsOnPostProcessor; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration.LiquibaseNamedParameterJdbcOperationsDependsOnPostProcessor; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; @@ -71,7 +72,8 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; @Conditional(LiquibaseDataSourceCondition.class) @AutoConfigureAfter({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) @Import({ LiquibaseJdbcOperationsDependsOnPostProcessor.class, - LiquibaseNamedParameterJdbcOperationsDependsOnPostProcessor.class }) + LiquibaseNamedParameterJdbcOperationsDependsOnPostProcessor.class, + LiquibaseEntityManagerFactoryDependsOnPostProcessor.class }) public class LiquibaseAutoConfiguration { @Bean @@ -83,7 +85,6 @@ public class LiquibaseAutoConfiguration { @Configuration(proxyBeanMethods = false) @ConditionalOnMissingBean(SpringLiquibase.class) @EnableConfigurationProperties({ DataSourceProperties.class, LiquibaseProperties.class }) - @Import(LiquibaseEntityManagerFactoryDependsOnPostProcessor.class) public static class LiquibaseConfiguration { private final LiquibaseProperties properties; 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 349e881bb4..29d433e30f 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 @@ -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.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.context.event.ApplicationStartingEvent; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener; @@ -332,6 +333,16 @@ class LiquibaseAutoConfigurationTests { }); } + @Test + void userConfigurationEntityManagerFactoryDependency() { + this.contextRunner.withConfiguration(AutoConfigurations.of(HibernateJpaAutoConfiguration.class)) + .withUserConfiguration(LiquibaseUserConfiguration.class, EmbeddedDataSourceConfiguration.class) + .run((context) -> { + BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("entityManagerFactory"); + assertThat(beanDefinition.getDependsOn()).containsExactly("springLiquibase"); + }); + } + private ContextConsumer assertLiquibase(Consumer consumer) { return (context) -> { assertThat(context).hasSingleBean(SpringLiquibase.class); From dccb8422866f30a7c7a7e847da7caf325d459b6f Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 22 Oct 2019 17:44:04 +0200 Subject: [PATCH 2/2] Polish "Apply dependsOn semantic between Liquibase and JPA" See gh-18673 --- .../liquibase/LiquibaseAutoConfiguration.java | 6 +++--- .../liquibase/LiquibaseAutoConfigurationTests.java | 12 ++++++------ 2 files changed, 9 insertions(+), 9 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 ba51aadb80..2d165d52fe 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 @@ -71,9 +71,9 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; @ConditionalOnProperty(prefix = "spring.liquibase", name = "enabled", matchIfMissing = true) @Conditional(LiquibaseDataSourceCondition.class) @AutoConfigureAfter({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) -@Import({ LiquibaseJdbcOperationsDependsOnPostProcessor.class, - LiquibaseNamedParameterJdbcOperationsDependsOnPostProcessor.class, - LiquibaseEntityManagerFactoryDependsOnPostProcessor.class }) +@Import({ LiquibaseEntityManagerFactoryDependsOnPostProcessor.class, + LiquibaseJdbcOperationsDependsOnPostProcessor.class, + LiquibaseNamedParameterJdbcOperationsDependsOnPostProcessor.class }) public class LiquibaseAutoConfiguration { @Bean 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 29d433e30f..8774a35154 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 @@ -324,21 +324,21 @@ class LiquibaseAutoConfigurationTests { } @Test - void userConfigurationJdbcTemplateDependency() { - this.contextRunner.withConfiguration(AutoConfigurations.of(JdbcTemplateAutoConfiguration.class)) + void userConfigurationEntityManagerFactoryDependency() { + this.contextRunner.withConfiguration(AutoConfigurations.of(HibernateJpaAutoConfiguration.class)) .withUserConfiguration(LiquibaseUserConfiguration.class, EmbeddedDataSourceConfiguration.class) .run((context) -> { - BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("jdbcTemplate"); + BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("entityManagerFactory"); assertThat(beanDefinition.getDependsOn()).containsExactly("springLiquibase"); }); } @Test - void userConfigurationEntityManagerFactoryDependency() { - this.contextRunner.withConfiguration(AutoConfigurations.of(HibernateJpaAutoConfiguration.class)) + void userConfigurationJdbcTemplateDependency() { + this.contextRunner.withConfiguration(AutoConfigurations.of(JdbcTemplateAutoConfiguration.class)) .withUserConfiguration(LiquibaseUserConfiguration.class, EmbeddedDataSourceConfiguration.class) .run((context) -> { - BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("entityManagerFactory"); + BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("jdbcTemplate"); assertThat(beanDefinition.getDependsOn()).containsExactly("springLiquibase"); }); }