From 42841b895f4ddcc89644d3abdf95059e025ddd88 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sun, 14 Mar 2021 20:54:57 +0900 Subject: [PATCH 1/2] Improve error message when no resources exist at a script location See gh-25620 --- .../boot/autoconfigure/jdbc/DataSourceInitializer.java | 4 ++-- .../jdbc/DataSourceInitializerInvokerTests.java | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java index 86c3baa1b9..fe9acb8d60 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -161,7 +161,7 @@ class DataSourceInitializer { } else if (validate) { throw new InvalidConfigurationPropertyValueException(propertyName, resource, - "The specified resource does not exist."); + "Resource '" + location + "' does not exist."); } } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java index 2323884123..6d846c1fde 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -221,8 +221,10 @@ class DataSourceInitializerInvokerTests { "spring.datasource.schema:classpath:does/not/exist.sql").run((context) -> { assertThat(context).hasFailed(); assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class); - assertThat(context.getStartupFailure()).hasMessageContaining("does/not/exist.sql"); + assertThat(context.getStartupFailure()).hasMessageContaining("[does/not/exist.sql]"); assertThat(context.getStartupFailure()).hasMessageContaining("spring.datasource.schema"); + assertThat(context.getStartupFailure()) + .hasMessageContaining("Resource 'classpath:does/not/exist.sql' does not exist."); }); } @@ -233,8 +235,10 @@ class DataSourceInitializerInvokerTests { "spring.datasource.data:classpath:does/not/exist.sql").run((context) -> { assertThat(context).hasFailed(); assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class); - assertThat(context.getStartupFailure()).hasMessageContaining("does/not/exist.sql"); + assertThat(context.getStartupFailure()).hasMessageContaining("[does/not/exist.sql]"); assertThat(context.getStartupFailure()).hasMessageContaining("spring.datasource.data"); + assertThat(context.getStartupFailure()) + .hasMessageContaining("Resource 'classpath:does/not/exist.sql' does not exist."); }); } From a832cc9ccd3d0f87cfcd5c38f8f18e113a933527 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 16 Mar 2021 16:20:11 +0000 Subject: [PATCH 2/2] Polish "Improve error message when no resources exist at a script location" See gh-25620 --- .../boot/autoconfigure/jdbc/DataSourceInitializer.java | 2 +- .../jdbc/DataSourceInitializerInvokerTests.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java index fe9acb8d60..e8f23e9148 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java @@ -161,7 +161,7 @@ class DataSourceInitializer { } else if (validate) { throw new InvalidConfigurationPropertyValueException(propertyName, resource, - "Resource '" + location + "' does not exist."); + "No resources were found at location '" + location + "'."); } } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java index 6d846c1fde..4d0100c514 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java @@ -223,8 +223,8 @@ class DataSourceInitializerInvokerTests { assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class); assertThat(context.getStartupFailure()).hasMessageContaining("[does/not/exist.sql]"); assertThat(context.getStartupFailure()).hasMessageContaining("spring.datasource.schema"); - assertThat(context.getStartupFailure()) - .hasMessageContaining("Resource 'classpath:does/not/exist.sql' does not exist."); + assertThat(context.getStartupFailure()).hasMessageContaining( + "No resources were found at location 'classpath:does/not/exist.sql'."); }); } @@ -237,8 +237,8 @@ class DataSourceInitializerInvokerTests { assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class); assertThat(context.getStartupFailure()).hasMessageContaining("[does/not/exist.sql]"); assertThat(context.getStartupFailure()).hasMessageContaining("spring.datasource.data"); - assertThat(context.getStartupFailure()) - .hasMessageContaining("Resource 'classpath:does/not/exist.sql' does not exist."); + assertThat(context.getStartupFailure()).hasMessageContaining( + "No resources were found at location 'classpath:does/not/exist.sql'."); }); }