Skip to content

Commit fe63865

Browse files
committed
Merge pull request #17805 from ahrytsiuk
* pr/17805: Polish "Set up SpringLiquibase beans' dependencies by type rather than name" Add missing javadoc Set up SpringLiquibase beans' dependencies by type rather than name Closes gh-17805
2 parents 24f6c9e + 0187e51 commit fe63865

File tree

5 files changed

+88
-3
lines changed

5 files changed

+88
-3
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jpa/EntityManagerFactoryDependsOnPostProcessor.java

+16
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,29 @@
3131
* @author Dave Syer
3232
* @author Phillip Webb
3333
* @author Andy Wilkinson
34+
* @author Andrii Hrytsiuk
3435
* @since 1.1.0
3536
* @see BeanDefinition#setDependsOn(String[])
3637
*/
3738
public class EntityManagerFactoryDependsOnPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor {
3839

40+
/**
41+
* Creates a new {@code EntityManagerFactoryDependsOnPostProcessor} that will set up
42+
* dependencies upon beans with the given names.
43+
* @param dependsOn names of the beans to depend upon
44+
*/
3945
public EntityManagerFactoryDependsOnPostProcessor(String... dependsOn) {
4046
super(EntityManagerFactory.class, AbstractEntityManagerFactoryBean.class, dependsOn);
4147
}
4248

49+
/**
50+
* Creates a new {@code EntityManagerFactoryDependsOnPostProcessor} that will set up
51+
* dependencies upon beans with the given types.
52+
* @param dependsOn types of the beans to depend upon
53+
* @since 2.1.8
54+
*/
55+
public EntityManagerFactoryDependsOnPostProcessor(Class<?>... dependsOn) {
56+
super(EntityManagerFactory.class, AbstractEntityManagerFactoryBean.class, dependsOn);
57+
}
58+
4359
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcOperationsDependsOnPostProcessor.java

+16
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,29 @@
2929
* @author Dave Syer
3030
* @author Phillip Webb
3131
* @author Andy Wilkinson
32+
* @author Andrii Hrytsiuk
3233
* @since 2.0.4
3334
* @see BeanDefinition#setDependsOn(String[])
3435
*/
3536
public class JdbcOperationsDependsOnPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor {
3637

38+
/**
39+
* Creates a new {@code JdbcOperationsDependsOnPostProcessor} that will set up
40+
* dependencies upon beans with the given names.
41+
* @param dependsOn names of the beans to depend upon
42+
*/
3743
public JdbcOperationsDependsOnPostProcessor(String... dependsOn) {
3844
super(JdbcOperations.class, dependsOn);
3945
}
4046

47+
/**
48+
* Creates a new {@code JdbcOperationsDependsOnPostProcessor} that will set up
49+
* dependencies upon beans with the given types.
50+
* @param dependsOn types of the beans to depend upon
51+
* @since 2.1.8
52+
*/
53+
public JdbcOperationsDependsOnPostProcessor(Class<?>... dependsOn) {
54+
super(JdbcOperations.class, dependsOn);
55+
}
56+
4157
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/NamedParameterJdbcOperationsDependsOnPostProcessor.java

+16
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,29 @@
2727
* beans.
2828
*
2929
* @author Dan Zheng
30+
* @author Andrii Hrytsiuk
3031
* @since 2.1.4
3132
* @see BeanDefinition#setDependsOn(String[])
3233
*/
3334
public class NamedParameterJdbcOperationsDependsOnPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor {
3435

36+
/**
37+
* Creates a new {@code NamedParameterJdbcOperationsDependsOnPostProcessor} that will
38+
* set up dependencies upon beans with the given names.
39+
* @param dependsOn names of the beans to depend upon
40+
*/
3541
public NamedParameterJdbcOperationsDependsOnPostProcessor(String... dependsOn) {
3642
super(NamedParameterJdbcOperations.class, dependsOn);
3743
}
3844

45+
/**
46+
* Creates a new {@code NamedParameterJdbcOperationsDependsOnPostProcessor} that will
47+
* set up dependencies upon beans with the given types.
48+
* @param dependsOn types of the beans to depend upon
49+
* @since 2.1.8
50+
*/
51+
public NamedParameterJdbcOperationsDependsOnPostProcessor(Class<?>... dependsOn) {
52+
super(NamedParameterJdbcOperations.class, dependsOn);
53+
}
54+
3955
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private String getProperty(Supplier<String> property, Supplier<String> defaultVa
165165
protected static class LiquibaseJpaDependencyConfiguration extends EntityManagerFactoryDependsOnPostProcessor {
166166

167167
public LiquibaseJpaDependencyConfiguration() {
168-
super("liquibase");
168+
super(SpringLiquibase.class);
169169
}
170170

171171
}
@@ -180,7 +180,7 @@ public LiquibaseJpaDependencyConfiguration() {
180180
protected static class LiquibaseJdbcOperationsDependencyConfiguration extends JdbcOperationsDependsOnPostProcessor {
181181

182182
public LiquibaseJdbcOperationsDependencyConfiguration() {
183-
super("liquibase");
183+
super(SpringLiquibase.class);
184184
}
185185

186186
}
@@ -196,7 +196,7 @@ protected static class LiquibaseNamedParameterJdbcOperationsDependencyConfigurat
196196
extends NamedParameterJdbcOperationsDependsOnPostProcessor {
197197

198198
public LiquibaseNamedParameterJdbcOperationsDependencyConfiguration() {
199-
super("liquibase");
199+
super(SpringLiquibase.class);
200200
}
201201

202202
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java

+37
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
import org.junit.rules.TemporaryFolder;
3333

3434
import org.springframework.beans.factory.BeanCreationException;
35+
import org.springframework.beans.factory.config.BeanDefinition;
3536
import org.springframework.boot.SpringApplication;
3637
import org.springframework.boot.autoconfigure.AutoConfigurations;
3738
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
39+
import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration;
3840
import org.springframework.boot.context.event.ApplicationStartingEvent;
3941
import org.springframework.boot.jdbc.DataSourceBuilder;
4042
import org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener;
@@ -61,6 +63,7 @@
6163
* @author Stephane Nicoll
6264
* @author Dominic Gunn
6365
* @author András Deák
66+
* @author Andrii Hrytsiuk
6467
*/
6568
public class LiquibaseAutoConfigurationTests {
6669

@@ -300,6 +303,26 @@ public void liquibaseDataSourceWithoutDataSourceAutoConfiguration() {
300303
});
301304
}
302305

306+
@Test
307+
public void userConfigurationBeans() {
308+
this.contextRunner
309+
.withUserConfiguration(LiquibaseUserConfiguration.class, EmbeddedDataSourceConfiguration.class)
310+
.run((context) -> {
311+
assertThat(context).hasBean("springLiquibase");
312+
assertThat(context).doesNotHaveBean("liquibase");
313+
});
314+
}
315+
316+
@Test
317+
public void userConfigurationJdbcTemplateDependency() {
318+
this.contextRunner.withConfiguration(AutoConfigurations.of(JdbcTemplateAutoConfiguration.class))
319+
.withUserConfiguration(LiquibaseUserConfiguration.class, EmbeddedDataSourceConfiguration.class)
320+
.run((context) -> {
321+
BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("jdbcTemplate");
322+
assertThat(beanDefinition.getDependsOn()).containsExactly("springLiquibase");
323+
});
324+
}
325+
303326
private ContextConsumer<AssertableApplicationContext> assertLiquibase(Consumer<SpringLiquibase> consumer) {
304327
return (context) -> {
305328
assertThat(context).hasSingleBean(SpringLiquibase.class);
@@ -325,4 +348,18 @@ public DataSource liquibaseDataSource() {
325348

326349
}
327350

351+
@Configuration
352+
static class LiquibaseUserConfiguration {
353+
354+
@Bean
355+
SpringLiquibase springLiquibase(DataSource dataSource) {
356+
SpringLiquibase liquibase = new SpringLiquibase();
357+
liquibase.setChangeLog("classpath:/db/changelog/db.changelog-master.yaml");
358+
liquibase.setShouldRun(true);
359+
liquibase.setDataSource(dataSource);
360+
return liquibase;
361+
}
362+
363+
}
364+
328365
}

0 commit comments

Comments
 (0)