Improve diagnostics when loading a property source from a file fails
Closes gh-8294
This commit is contained in:
parent
43f34546f6
commit
4b1e5e9c43
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
@ -208,12 +208,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
|||
protected void addPropertySources(ConfigurableEnvironment environment,
|
||||
ResourceLoader resourceLoader) {
|
||||
RandomValuePropertySource.addToEnvironment(environment);
|
||||
try {
|
||||
new Loader(environment, resourceLoader).load();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("Unable to load configuration files", ex);
|
||||
}
|
||||
new Loader(environment, resourceLoader).load();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -339,7 +334,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
|||
: resourceLoader;
|
||||
}
|
||||
|
||||
public void load() throws IOException {
|
||||
public void load() {
|
||||
this.propertiesLoader = new PropertySourcesLoader();
|
||||
this.activatedProfiles = false;
|
||||
this.profiles = Collections.asLifoQueue(new LinkedList<Profile>());
|
||||
|
|
@ -423,8 +418,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
|||
return unprocessedActiveProfiles;
|
||||
}
|
||||
|
||||
private void load(String location, String name, Profile profile)
|
||||
throws IOException {
|
||||
private void load(String location, String name, Profile profile) {
|
||||
String group = "profile=" + (profile == null ? "" : profile);
|
||||
if (!StringUtils.hasText(name)) {
|
||||
// Try to load directly from the location
|
||||
|
|
@ -456,6 +450,18 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
|||
}
|
||||
|
||||
private PropertySource<?> loadIntoGroup(String identifier, String location,
|
||||
Profile profile) {
|
||||
try {
|
||||
return doLoadIntoGroup(identifier, location, profile);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(
|
||||
"Failed to load property source from location '" + location + "'",
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
private PropertySource<?> doLoadIntoGroup(String identifier, String location,
|
||||
Profile profile) throws IOException {
|
||||
Resource resource = this.resourceLoader.getResource(location);
|
||||
PropertySource<?> propertySource = null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue