Skip to content

Commit 4b1e5e9

Browse files
committed
Improve diagnostics when loading a property source from a file fails
Closes gh-8294
1 parent 43f3454 commit 4b1e5e9

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 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.
@@ -208,12 +208,7 @@ private void onApplicationPreparedEvent(ApplicationEvent event) {
208208
protected void addPropertySources(ConfigurableEnvironment environment,
209209
ResourceLoader resourceLoader) {
210210
RandomValuePropertySource.addToEnvironment(environment);
211-
try {
212-
new Loader(environment, resourceLoader).load();
213-
}
214-
catch (IOException ex) {
215-
throw new IllegalStateException("Unable to load configuration files", ex);
216-
}
211+
new Loader(environment, resourceLoader).load();
217212
}
218213

219214
/**
@@ -339,7 +334,7 @@ private class Loader {
339334
: resourceLoader;
340335
}
341336

342-
public void load() throws IOException {
337+
public void load() {
343338
this.propertiesLoader = new PropertySourcesLoader();
344339
this.activatedProfiles = false;
345340
this.profiles = Collections.asLifoQueue(new LinkedList<Profile>());
@@ -423,8 +418,7 @@ private List<Profile> getUnprocessedActiveProfiles(
423418
return unprocessedActiveProfiles;
424419
}
425420

426-
private void load(String location, String name, Profile profile)
427-
throws IOException {
421+
private void load(String location, String name, Profile profile) {
428422
String group = "profile=" + (profile == null ? "" : profile);
429423
if (!StringUtils.hasText(name)) {
430424
// Try to load directly from the location
@@ -456,6 +450,18 @@ private void load(String location, String name, Profile profile)
456450
}
457451

458452
private PropertySource<?> loadIntoGroup(String identifier, String location,
453+
Profile profile) {
454+
try {
455+
return doLoadIntoGroup(identifier, location, profile);
456+
}
457+
catch (Exception ex) {
458+
throw new IllegalStateException(
459+
"Failed to load property source from location '" + location + "'",
460+
ex);
461+
}
462+
}
463+
464+
private PropertySource<?> doLoadIntoGroup(String identifier, String location,
459465
Profile profile) throws IOException {
460466
Resource resource = this.resourceLoader.getResource(location);
461467
PropertySource<?> propertySource = null;

0 commit comments

Comments
 (0)