Merge pull request #16947 from Alan Gomes
* gh-16947: Polish "Configure FluentConfiguration to use ResourceLoader's ClassLoader" Configure FluentConfiguration to use ResourceLoader's ClassLoader Closes gh-16947
This commit is contained in:
@@ -113,7 +113,8 @@ public class FlywayAutoConfiguration {
|
||||
ObjectProvider<FlywayConfigurationCustomizer> fluentConfigurationCustomizers,
|
||||
ObjectProvider<Callback> callbacks,
|
||||
ObjectProvider<FlywayCallback> flywayCallbacks) {
|
||||
FluentConfiguration configuration = new FluentConfiguration();
|
||||
FluentConfiguration configuration = new FluentConfiguration(
|
||||
resourceLoader.getClassLoader());
|
||||
DataSource dataSourceToMigrate = configureDataSource(configuration,
|
||||
properties, dataSourceProperties, flywayDataSource.getIfAvailable(),
|
||||
dataSource.getIfAvailable());
|
||||
|
||||
@@ -48,6 +48,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -470,6 +472,17 @@ public class FlywayAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customFlywayClassLoader() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class,
|
||||
ResourceLoaderConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(Flyway.class);
|
||||
Flyway flyway = context.getBean(Flyway.class);
|
||||
assertThat(flyway.getConfiguration().getClassLoader())
|
||||
.isInstanceOf(CustomClassLoader.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
protected static class FlywayDataSourceConfiguration {
|
||||
|
||||
@@ -489,6 +502,18 @@ public class FlywayAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
protected static class ResourceLoaderConfiguration {
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public ResourceLoader customClassLoader() {
|
||||
return new DefaultResourceLoader(
|
||||
new CustomClassLoader(getClass().getClassLoader()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
protected static class CustomFlywayMigrationInitializer {
|
||||
|
||||
@@ -604,4 +629,12 @@ public class FlywayAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
private static final class CustomClassLoader extends ClassLoader {
|
||||
|
||||
private CustomClassLoader(ClassLoader parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user