Skip to content

Commit 62f696d

Browse files
committed
Merge pull request #20617 from ta7uw
* pr/20617: Polish "Fix @FlywayDataSource with multiple data sources" Fix @FlywayDataSource with multiple data sources Closes gh-20617
2 parents 7be3db2 + 8f265f8 commit 62f696d

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -74,6 +74,7 @@
7474
* @author Stephane Nicoll
7575
* @author Dominic Gunn
7676
* @author András Deák
77+
* @author Takaaki Shimbo
7778
*/
7879
class FlywayAutoConfigurationTests {
7980

@@ -158,6 +159,15 @@ void flywayDataSourceWithoutDataSourceAutoConfiguration() {
158159
});
159160
}
160161

162+
@Test
163+
void flywayMultipleDataSources() {
164+
this.contextRunner.withUserConfiguration(FlywayMultipleDataSourcesConfiguration.class).run((context) -> {
165+
assertThat(context).hasSingleBean(Flyway.class);
166+
assertThat(context.getBean(Flyway.class).getConfiguration().getDataSource())
167+
.isEqualTo(context.getBean("flywayDataSource"));
168+
});
169+
}
170+
161171
@Test
162172
void schemaManagementProviderDetectsDataSource() {
163173
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)