Merge branch '2.1.x'

Closes gh-18103
pull/18122/head
Andy Wilkinson 5 years ago
commit 2dea534a0e

@ -301,7 +301,7 @@ public class FlywayAutoConfiguration {
/** /**
* Additional configuration to ensure that {@link EntityManagerFactory} beans depend * Additional configuration to ensure that {@link EntityManagerFactory} beans depend
* on the {@code flyway} bean. * on any {@link Flyway} beans.
*/ */
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnClass(LocalContainerEntityManagerFactoryBean.class) @ConditionalOnClass(LocalContainerEntityManagerFactoryBean.class)
@ -309,14 +309,14 @@ public class FlywayAutoConfiguration {
protected static class FlywayJpaDependencyConfiguration extends EntityManagerFactoryDependsOnPostProcessor { protected static class FlywayJpaDependencyConfiguration extends EntityManagerFactoryDependsOnPostProcessor {
public FlywayJpaDependencyConfiguration() { public FlywayJpaDependencyConfiguration() {
super("flyway"); super(Flyway.class);
} }
} }
/** /**
* Additional configuration to ensure that {@link JdbcOperations} beans depend on the * Additional configuration to ensure that {@link JdbcOperations} beans depend on any
* {@code flyway} bean. * {@link Flyway} beans.
*/ */
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnClass(JdbcOperations.class) @ConditionalOnClass(JdbcOperations.class)
@ -324,14 +324,14 @@ public class FlywayAutoConfiguration {
protected static class FlywayJdbcOperationsDependencyConfiguration extends JdbcOperationsDependsOnPostProcessor { protected static class FlywayJdbcOperationsDependencyConfiguration extends JdbcOperationsDependsOnPostProcessor {
public FlywayJdbcOperationsDependencyConfiguration() { public FlywayJdbcOperationsDependencyConfiguration() {
super("flyway"); super(Flyway.class);
} }
} }
/** /**
* Additional configuration to ensure that {@link NamedParameterJdbcOperations} beans * Additional configuration to ensure that {@link NamedParameterJdbcOperations} beans
* depend on the {@code flyway} bean. * depend on any {@link Flyway} beans.
*/ */
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnClass(NamedParameterJdbcOperations.class) @ConditionalOnClass(NamedParameterJdbcOperations.class)
@ -340,7 +340,7 @@ public class FlywayAutoConfiguration {
extends NamedParameterJdbcOperationsDependsOnPostProcessor { extends NamedParameterJdbcOperationsDependsOnPostProcessor {
public FlywayNamedParameterJdbcOperationsDependencyConfiguration() { public FlywayNamedParameterJdbcOperationsDependencyConfiguration() {
super("flyway"); super(Flyway.class);
} }
} }

@ -49,6 +49,10 @@ import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -293,6 +297,13 @@ class FlywayAutoConfigurationTests {
.run((context) -> assertThat(context).hasNotFailed()); .run((context) -> assertThat(context).hasNotFailed());
} }
@Test
void customFlywayWithJdbc() {
this.contextRunner
.withUserConfiguration(EmbeddedDataSourceConfiguration.class, CustomFlywayWithJdbcConfiguration.class)
.run((context) -> assertThat(context).hasNotFailed());
}
@Test @Test
void overrideBaselineVersionString() { void overrideBaselineVersionString() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
@ -530,7 +541,7 @@ class FlywayAutoConfigurationTests {
} }
@Bean @Bean
Flyway flyway() { Flyway customFlyway() {
return Flyway.configure().load(); return Flyway.configure().load();
} }
@ -545,6 +556,32 @@ class FlywayAutoConfigurationTests {
} }
@Configuration
static class CustomFlywayWithJdbcConfiguration {
private final DataSource dataSource;
protected CustomFlywayWithJdbcConfiguration(DataSource dataSource) {
this.dataSource = dataSource;
}
@Bean
Flyway customFlyway() {
return Flyway.configure().load();
}
@Bean
JdbcOperations jdbcOperations() {
return new JdbcTemplate(this.dataSource);
}
@Bean
NamedParameterJdbcOperations namedParameterJdbcOperations() {
return new NamedParameterJdbcTemplate(this.dataSource);
}
}
@Component @Component
static class MockFlywayMigrationStrategy implements FlywayMigrationStrategy { static class MockFlywayMigrationStrategy implements FlywayMigrationStrategy {

Loading…
Cancel
Save