Skip to content

Commit 1a9065f

Browse files
committed
Merge branch '2.2.x'
Closes gh-20621
2 parents 34b7156 + 62f696d commit 1a9065f

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public Flyway flyway(FlywayProperties properties, DataSourceProperties dataSourc
125125
ObjectProvider<JavaMigration> javaMigrations, ObjectProvider<Callback> callbacks) {
126126
FluentConfiguration configuration = new FluentConfiguration(resourceLoader.getClassLoader());
127127
DataSource dataSourceToMigrate = configureDataSource(configuration, properties, dataSourceProperties,
128-
flywayDataSource.getIfAvailable(), dataSource.getIfAvailable());
128+
flywayDataSource.getIfAvailable(), dataSource.getIfUnique());
129129
checkLocationExists(dataSourceToMigrate, properties, resourceLoader);
130130
configureProperties(configuration, properties);
131131
List<Callback> orderedCallbacks = callbacks.orderedStream().collect(Collectors.toList());

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
* @author Stephane Nicoll
7878
* @author Dominic Gunn
7979
* @author András Deák
80+
* @author Takaaki Shimbo
8081
*/
8182
@ExtendWith(OutputCaptureExtension.class)
8283
class FlywayAutoConfigurationTests {
@@ -162,6 +163,15 @@ void flywayDataSourceWithoutDataSourceAutoConfiguration() {
162163
});
163164
}
164165

166+
@Test
167+
void flywayMultipleDataSources() {
168+
this.contextRunner.withUserConfiguration(FlywayMultipleDataSourcesConfiguration.class).run((context) -> {
169+
assertThat(context).hasSingleBean(Flyway.class);
170+
assertThat(context.getBean(Flyway.class).getConfiguration().getDataSource())
171+
.isEqualTo(context.getBean("flywayDataSource"));
172+
});
173+
}
174+
165175
@Test
166176
void schemaManagementProviderDetectsDataSource() {
167177
this.contextRunner
@@ -509,6 +519,27 @@ DataSource flywayDataSource() {
509519

510520
}
511521

522+
@Configuration(proxyBeanMethods = false)
523+
static class FlywayMultipleDataSourcesConfiguration {
524+
525+
@Bean
526+
DataSource firstDataSource() {
527+
return DataSourceBuilder.create().url("jdbc:hsqldb:mem:first").username("sa").build();
528+
}
529+
530+
@Bean
531+
DataSource secondDataSource() {
532+
return DataSourceBuilder.create().url("jdbc:hsqldb:mem:second").username("sa").build();
533+
}
534+
535+
@FlywayDataSource
536+
@Bean
537+
DataSource flywayDataSource() {
538+
return DataSourceBuilder.create().url("jdbc:hsqldb:mem:flywaytest").username("sa").build();
539+
}
540+
541+
}
542+
512543
@Configuration(proxyBeanMethods = false)
513544
static class FlywayJavaMigrationsConfiguration {
514545

0 commit comments

Comments
 (0)