Skip to content

Commit f59e337

Browse files
committed
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
2 parents 898b791 + 69a2982 commit f59e337

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ public Flyway flyway(FlywayProperties properties,
113113
ObjectProvider<FlywayConfigurationCustomizer> fluentConfigurationCustomizers,
114114
ObjectProvider<Callback> callbacks,
115115
ObjectProvider<FlywayCallback> flywayCallbacks) {
116-
FluentConfiguration configuration = new FluentConfiguration();
116+
FluentConfiguration configuration = new FluentConfiguration(
117+
resourceLoader.getClassLoader());
117118
DataSource dataSourceToMigrate = configureDataSource(configuration,
118119
properties, dataSourceProperties, flywayDataSource.getIfAvailable(),
119120
dataSource.getIfAvailable());

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java

+33
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import org.springframework.context.annotation.Primary;
4949
import org.springframework.core.Ordered;
5050
import org.springframework.core.annotation.Order;
51+
import org.springframework.core.io.DefaultResourceLoader;
52+
import org.springframework.core.io.ResourceLoader;
5153
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
5254
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
5355
import org.springframework.stereotype.Component;
@@ -470,6 +472,17 @@ public void undoSqlMigrationPrefix() {
470472
});
471473
}
472474

475+
@Test
476+
public void customFlywayClassLoader() {
477+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class,
478+
ResourceLoaderConfiguration.class).run((context) -> {
479+
assertThat(context).hasSingleBean(Flyway.class);
480+
Flyway flyway = context.getBean(Flyway.class);
481+
assertThat(flyway.getConfiguration().getClassLoader())
482+
.isInstanceOf(CustomClassLoader.class);
483+
});
484+
}
485+
473486
@Configuration(proxyBeanMethods = false)
474487
protected static class FlywayDataSourceConfiguration {
475488

@@ -489,6 +502,18 @@ public DataSource flywayDataSource() {
489502

490503
}
491504

505+
@Configuration(proxyBeanMethods = false)
506+
protected static class ResourceLoaderConfiguration {
507+
508+
@Bean
509+
@Primary
510+
public ResourceLoader customClassLoader() {
511+
return new DefaultResourceLoader(
512+
new CustomClassLoader(getClass().getClassLoader()));
513+
}
514+
515+
}
516+
492517
@Configuration(proxyBeanMethods = false)
493518
protected static class CustomFlywayMigrationInitializer {
494519

@@ -604,4 +629,12 @@ public FlywayConfigurationCustomizer customizerTwo() {
604629

605630
}
606631

632+
private static final class CustomClassLoader extends ClassLoader {
633+
634+
private CustomClassLoader(ClassLoader parent) {
635+
super(parent);
636+
}
637+
638+
}
639+
607640
}

0 commit comments

Comments
 (0)