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
pull/18689/head
Dmytro Nosan 5 years ago committed by Stephane Nicoll
parent d254c62712
commit bacd36f0cf

@ -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;

@ -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<AssertableApplicationContext> assertLiquibase(Consumer<SpringLiquibase> consumer) {
return (context) -> {
assertThat(context).hasSingleBean(SpringLiquibase.class);

Loading…
Cancel
Save