From 283b4a6ed28255e2368abba149a52c91b2bb5b78 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 8 Jul 2021 09:17:55 +0100 Subject: [PATCH] Improve error message for non-options-capable ConnectionFactory Fixes gh-26977 --- .../boot/r2dbc/EmbeddedDatabaseConnection.java | 4 +++- .../boot/r2dbc/EmbeddedDatabaseConnectionTests.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnection.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnection.java index 2012a7d639..67dd7b02b0 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnection.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnection.java @@ -101,7 +101,9 @@ public enum EmbeddedDatabaseConnection { OptionsCapableConnectionFactory optionsCapable = OptionsCapableConnectionFactory.unwrapFrom(connectionFactory); if (optionsCapable == null) { throw new IllegalArgumentException( - "Cannot determine database's type as ConnectionFactory is not options-capable"); + "Cannot determine database's type as ConnectionFactory is not options-capable. To be " + + "options-capable, a ConnectionFactory should be created with " + + ConnectionFactoryBuilder.class.getName()); } ConnectionFactoryOptions options = optionsCapable.getOptions(); for (EmbeddedDatabaseConnection candidate : values()) { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnectionTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnectionTests.java index 54729a2903..a5bab4f5b4 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnectionTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnectionTests.java @@ -89,7 +89,9 @@ class EmbeddedDatabaseConnectionTests { assertThatIllegalArgumentException() .isThrownBy(() -> EmbeddedDatabaseConnection .isEmbedded(ConnectionFactories.get("r2dbc:pool:h2:mem:///" + UUID.randomUUID()))) - .withMessage("Cannot determine database's type as ConnectionFactory is not options-capable"); + .withMessage("Cannot determine database's type as ConnectionFactory is not options-capable. To be " + + "options-capable, a ConnectionFactory should be created with " + + "org.springframework.boot.r2dbc.ConnectionFactoryBuilder"); } static Stream urlParameters() {