Skip to content

Commit 42841b8

Browse files
uc4w6cwilkinsona
authored andcommitted
Improve error message when no resources exist at a script location
See gh-25620
1 parent 226ee61 commit 42841b8

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 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.
@@ -161,7 +161,7 @@ private List<Resource> getResources(String propertyName, List<String> locations,
161161
}
162162
else if (validate) {
163163
throw new InvalidConfigurationPropertyValueException(propertyName, resource,
164-
"The specified resource does not exist.");
164+
"Resource '" + location + "' does not exist.");
165165
}
166166
}
167167
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java

Lines changed: 7 additions & 3 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-2021 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.
@@ -221,8 +221,10 @@ void testDataSourceInitializedWithInvalidSchemaResource() {
221221
"spring.datasource.schema:classpath:does/not/exist.sql").run((context) -> {
222222
assertThat(context).hasFailed();
223223
assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class);
224-
assertThat(context.getStartupFailure()).hasMessageContaining("does/not/exist.sql");
224+
assertThat(context.getStartupFailure()).hasMessageContaining("[does/not/exist.sql]");
225225
assertThat(context.getStartupFailure()).hasMessageContaining("spring.datasource.schema");
226+
assertThat(context.getStartupFailure())
227+
.hasMessageContaining("Resource 'classpath:does/not/exist.sql' does not exist.");
226228
});
227229
}
228230

@@ -233,8 +235,10 @@ void dataSourceInitializedWithInvalidDataResource() {
233235
"spring.datasource.data:classpath:does/not/exist.sql").run((context) -> {
234236
assertThat(context).hasFailed();
235237
assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class);
236-
assertThat(context.getStartupFailure()).hasMessageContaining("does/not/exist.sql");
238+
assertThat(context.getStartupFailure()).hasMessageContaining("[does/not/exist.sql]");
237239
assertThat(context.getStartupFailure()).hasMessageContaining("spring.datasource.data");
240+
assertThat(context.getStartupFailure())
241+
.hasMessageContaining("Resource 'classpath:does/not/exist.sql' does not exist.");
238242
});
239243
}
240244

0 commit comments

Comments
 (0)