From e55948456f754313e65b24a170fdde99798ec74c Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 26 May 2021 14:59:20 -0700 Subject: [PATCH] Respect custom username/password properties Fix a bug in `DataSourceInitializationConfiguration` that was stopping custom username/password properties from being applied. Fixes gh-26676 --- .../jdbc/DataSourceInitializationConfiguration.java | 2 +- .../jdbc/DataSourceInitializationIntegrationTests.java | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationConfiguration.java index f495550f68..4b4bd76bbf 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationConfiguration.java @@ -64,7 +64,7 @@ class DataSourceInitializationConfiguration { private static DataSource determineDataSource(Supplier 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(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationIntegrationTests.java index acb667837a..c8a8d279ed 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationIntegrationTests.java @@ -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"); }); }