Respect custom username/password properties

Fix a bug in `DataSourceInitializationConfiguration` that was stopping
custom username/password properties from being applied.

Fixes gh-26676
pull/26677/head
Phillip Webb 4 years ago
parent 7d6093680d
commit e55948456f

@ -64,7 +64,7 @@ class DataSourceInitializationConfiguration {
private static DataSource determineDataSource(Supplier<DataSource> dataSource, String username, String password) {
if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
DataSourceBuilder.derivedFrom(dataSource.get()).type(SimpleDriverDataSource.class).username(username)
return DataSourceBuilder.derivedFrom(dataSource.get()).type(SimpleDriverDataSource.class).username(username)
.password(password).build();
}
return dataSource.get();

@ -198,7 +198,9 @@ class DataSourceInitializationIntegrationTests {
"spring.datasource.schema-username:admin", "spring.datasource.schema-password:admin")
.run((context) -> {
assertThat(context).hasFailed();
assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class);
assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class)
.hasMessageContaining("invalid authorization specification");
context.getStartupFailure().printStackTrace();
});
}
@ -212,7 +214,8 @@ class DataSourceInitializationIntegrationTests {
"spring.datasource.data-username:admin", "spring.datasource.data-password:admin")
.run((context) -> {
assertThat(context).hasFailed();
assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class);
assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class)
.hasMessageContaining("invalid authorization specification");
});
}

Loading…
Cancel
Save