commit
76dfe1aae4
|
|
@ -31,13 +31,29 @@ import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean;
|
|||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
* @author Andrii Hrytsiuk
|
||||
* @since 1.1.0
|
||||
* @see BeanDefinition#setDependsOn(String[])
|
||||
*/
|
||||
public class EntityManagerFactoryDependsOnPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor {
|
||||
|
||||
/**
|
||||
* Creates a new {@code EntityManagerFactoryDependsOnPostProcessor} that will set up
|
||||
* dependencies upon beans with the given names.
|
||||
* @param dependsOn names of the beans to depend upon
|
||||
*/
|
||||
public EntityManagerFactoryDependsOnPostProcessor(String... dependsOn) {
|
||||
super(EntityManagerFactory.class, AbstractEntityManagerFactoryBean.class, dependsOn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code EntityManagerFactoryDependsOnPostProcessor} that will set up
|
||||
* dependencies upon beans with the given types.
|
||||
* @param dependsOn types of the beans to depend upon
|
||||
* @since 2.1.8
|
||||
*/
|
||||
public EntityManagerFactoryDependsOnPostProcessor(Class<?>... dependsOn) {
|
||||
super(EntityManagerFactory.class, AbstractEntityManagerFactoryBean.class, dependsOn);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,13 +29,29 @@ import org.springframework.jdbc.core.JdbcOperations;
|
|||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
* @author Andrii Hrytsiuk
|
||||
* @since 2.0.4
|
||||
* @see BeanDefinition#setDependsOn(String[])
|
||||
*/
|
||||
public class JdbcOperationsDependsOnPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor {
|
||||
|
||||
/**
|
||||
* Creates a new {@code JdbcOperationsDependsOnPostProcessor} that will set up
|
||||
* dependencies upon beans with the given names.
|
||||
* @param dependsOn names of the beans to depend upon
|
||||
*/
|
||||
public JdbcOperationsDependsOnPostProcessor(String... dependsOn) {
|
||||
super(JdbcOperations.class, dependsOn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code JdbcOperationsDependsOnPostProcessor} that will set up
|
||||
* dependencies upon beans with the given types.
|
||||
* @param dependsOn types of the beans to depend upon
|
||||
* @since 2.1.8
|
||||
*/
|
||||
public JdbcOperationsDependsOnPostProcessor(Class<?>... dependsOn) {
|
||||
super(JdbcOperations.class, dependsOn);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,13 +27,29 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
|||
* beans.
|
||||
*
|
||||
* @author Dan Zheng
|
||||
* @author Andrii Hrytsiuk
|
||||
* @since 2.1.4
|
||||
* @see BeanDefinition#setDependsOn(String[])
|
||||
*/
|
||||
public class NamedParameterJdbcOperationsDependsOnPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor {
|
||||
|
||||
/**
|
||||
* Creates a new {@code NamedParameterJdbcOperationsDependsOnPostProcessor} that will
|
||||
* set up dependencies upon beans with the given names.
|
||||
* @param dependsOn names of the beans to depend upon
|
||||
*/
|
||||
public NamedParameterJdbcOperationsDependsOnPostProcessor(String... dependsOn) {
|
||||
super(NamedParameterJdbcOperations.class, dependsOn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code NamedParameterJdbcOperationsDependsOnPostProcessor} that will
|
||||
* set up dependencies upon beans with the given types.
|
||||
* @param dependsOn types of the beans to depend upon
|
||||
* @since 2.1.8
|
||||
*/
|
||||
public NamedParameterJdbcOperationsDependsOnPostProcessor(Class<?>... dependsOn) {
|
||||
super(NamedParameterJdbcOperations.class, dependsOn);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ public class LiquibaseAutoConfiguration {
|
|||
protected static class LiquibaseJpaDependencyConfiguration extends EntityManagerFactoryDependsOnPostProcessor {
|
||||
|
||||
public LiquibaseJpaDependencyConfiguration() {
|
||||
super("liquibase");
|
||||
super(SpringLiquibase.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -176,7 +176,7 @@ public class LiquibaseAutoConfiguration {
|
|||
protected static class LiquibaseJdbcOperationsDependencyConfiguration extends JdbcOperationsDependsOnPostProcessor {
|
||||
|
||||
public LiquibaseJdbcOperationsDependencyConfiguration() {
|
||||
super("liquibase");
|
||||
super(SpringLiquibase.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ public class LiquibaseAutoConfiguration {
|
|||
extends NamedParameterJdbcOperationsDependsOnPostProcessor {
|
||||
|
||||
public LiquibaseNamedParameterJdbcOperationsDependencyConfiguration() {
|
||||
super("liquibase");
|
||||
super(SpringLiquibase.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,9 +36,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
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.context.event.ApplicationStartingEvent;
|
||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||
import org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener;
|
||||
|
|
@ -65,6 +67,7 @@ import static org.assertj.core.api.Assertions.contentOf;
|
|||
* @author Stephane Nicoll
|
||||
* @author Dominic Gunn
|
||||
* @author András Deák
|
||||
* @author Andrii Hrytsiuk
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class LiquibaseAutoConfigurationTests {
|
||||
|
|
@ -309,6 +312,26 @@ class LiquibaseAutoConfigurationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void userConfigurationBeans() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(LiquibaseUserConfiguration.class, EmbeddedDataSourceConfiguration.class)
|
||||
.run((context) -> {
|
||||
assertThat(context).hasBean("springLiquibase");
|
||||
assertThat(context).doesNotHaveBean("liquibase");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void userConfigurationJdbcTemplateDependency() {
|
||||
this.contextRunner.withConfiguration(AutoConfigurations.of(JdbcTemplateAutoConfiguration.class))
|
||||
.withUserConfiguration(LiquibaseUserConfiguration.class, EmbeddedDataSourceConfiguration.class)
|
||||
.run((context) -> {
|
||||
BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("jdbcTemplate");
|
||||
assertThat(beanDefinition.getDependsOn()).containsExactly("springLiquibase");
|
||||
});
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> assertLiquibase(Consumer<SpringLiquibase> consumer) {
|
||||
return (context) -> {
|
||||
assertThat(context).hasSingleBean(SpringLiquibase.class);
|
||||
|
|
@ -334,4 +357,18 @@ class LiquibaseAutoConfigurationTests {
|
|||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class LiquibaseUserConfiguration {
|
||||
|
||||
@Bean
|
||||
SpringLiquibase springLiquibase(DataSource dataSource) {
|
||||
SpringLiquibase liquibase = new SpringLiquibase();
|
||||
liquibase.setChangeLog("classpath:/db/changelog/db.changelog-master.yaml");
|
||||
liquibase.setShouldRun(true);
|
||||
liquibase.setDataSource(dataSource);
|
||||
return liquibase;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue