Make Flyway and Liquibase auto-config back off without spring-jdbc

The auto-config requires Spring JDBC for DataSource creation from
spring.flyway.url or spring.liquibase.url, checking Flyway migrations
exist, etc. Without it, the application fails to start due to missing
spring-jdbc classes.

This commit updates the auto-config so that it backs off in the
absence of spring-jdbc.

Closes gh-26849
pull/27348/head
Andy Wilkinson 3 years ago
parent 7ba575d392
commit a1e279f736

@ -115,6 +115,7 @@ public class FlywayAutoConfiguration {
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(JdbcUtils.class)
@ConditionalOnMissingBean(Flyway.class)
@EnableConfigurationProperties({ DataSourceProperties.class, FlywayProperties.class })
@Import({ FlywayMigrationInitializerEntityManagerFactoryDependsOnPostProcessor.class,

@ -52,6 +52,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.core.ConnectionCallback;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
@ -92,6 +93,7 @@ public class LiquibaseAutoConfiguration {
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(ConnectionCallback.class)
@ConditionalOnMissingBean(SpringLiquibase.class)
@EnableConfigurationProperties({ DataSourceProperties.class, LiquibaseProperties.class })
public static class LiquibaseConfiguration {

@ -46,6 +46,7 @@ import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfigurati
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.jdbc.SchemaManagement;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
@ -104,6 +105,13 @@ class FlywayAutoConfigurationTests {
});
}
@Test
void backsOffWithFlywayUrlAndNoSpringJdbc() {
this.contextRunner.withPropertyValues("spring.flyway.url:jdbc:hsqldb:mem:" + UUID.randomUUID())
.withClassLoader(new FilteredClassLoader("org.springframework.jdbc"))
.run((context) -> assertThat(context).doesNotHaveBean(Flyway.class));
}
@Test
void createDataSourceWithUrl() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)

@ -21,6 +21,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;
import javax.sql.DataSource;
@ -104,6 +105,13 @@ class LiquibaseAutoConfigurationTests {
}));
}
@Test
void backsOffWithLiquibaseUrlAndNoSpringJdbc() {
this.contextRunner.withPropertyValues("spring.liquibase.url:jdbc:hsqldb:mem:" + UUID.randomUUID())
.withClassLoader(new FilteredClassLoader("org.springframework.jdbc"))
.run((context) -> assertThat(context).doesNotHaveBean(SpringLiquibase.class));
}
@Test
void createsDataSourceWhenSpringJdbcOnlyAvailableWithNoDataSourceBeanAndLiquibaseUrl() {
this.contextRunner.withPropertyValues("spring.liquibase.url:jdbc:hsqldb:mem:liquibase")

Loading…
Cancel
Save