Continue processing properties files on error
Prior to this commit, processing of multiple properties files discovered using a wildcard pattern would stop on any error encountered while processing a file or when an empty properties file was found, causing subsequent files from the pattern to be ignored. This commit changes the behavior such that subsequent files are processed on error or on an empty file. Fixes gh-20873
This commit is contained in:
parent
5afcaa7455
commit
ba4eec87e4
|
@ -503,16 +503,16 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
|||
|
||||
private void load(PropertySourceLoader loader, String location, Profile profile, DocumentFilter filter,
|
||||
DocumentConsumer consumer) {
|
||||
try {
|
||||
Resource[] resources = getResources(location);
|
||||
for (Resource resource : resources) {
|
||||
Resource[] resources = getResources(location);
|
||||
for (Resource resource : resources) {
|
||||
try {
|
||||
if (resource == null || !resource.exists()) {
|
||||
if (this.logger.isTraceEnabled()) {
|
||||
StringBuilder description = getDescription("Skipped missing config ", location, resource,
|
||||
profile);
|
||||
this.logger.trace(description);
|
||||
}
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
if (!StringUtils.hasText(StringUtils.getFilenameExtension(resource.getFilename()))) {
|
||||
if (this.logger.isTraceEnabled()) {
|
||||
|
@ -520,7 +520,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
|||
resource, profile);
|
||||
this.logger.trace(description);
|
||||
}
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
String name = (location.contains("*")) ? "applicationConfig: [" + resource.toString() + "]"
|
||||
: "applicationConfig: [" + location + "]";
|
||||
|
@ -531,7 +531,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
|||
profile);
|
||||
this.logger.trace(description);
|
||||
}
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
List<Document> loaded = new ArrayList<>();
|
||||
for (Document document : documents) {
|
||||
|
@ -551,9 +551,11 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Failed to load property source from location '" + location + "'", ex);
|
||||
catch (Exception ex) {
|
||||
StringBuilder description = getDescription("Failed to load property source from ", location,
|
||||
resource, profile);
|
||||
throw new IllegalStateException(description.toString(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1010,10 +1010,10 @@ class ConfigFileApplicationListenerTests {
|
|||
"spring.config.location=" + location);
|
||||
this.initializer.setSearchNames("testproperties");
|
||||
this.initializer.postProcessEnvironment(this.environment, this.application);
|
||||
String a = this.environment.getProperty("a.property");
|
||||
String b = this.environment.getProperty("b.property");
|
||||
assertThat(a).isEqualTo("apple");
|
||||
assertThat(b).isEqualTo("ball");
|
||||
String first = this.environment.getProperty("first.property");
|
||||
String second = this.environment.getProperty("second.property");
|
||||
assertThat(first).isEqualTo("apple");
|
||||
assertThat(second).isEqualTo("ball");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1023,10 +1023,10 @@ class ConfigFileApplicationListenerTests {
|
|||
"spring.config.location=" + location);
|
||||
this.initializer.setSearchNames("testproperties");
|
||||
this.initializer.postProcessEnvironment(this.environment, this.application);
|
||||
String a = this.environment.getProperty("a.property");
|
||||
String b = this.environment.getProperty("b.property");
|
||||
assertThat(a).isEqualTo("apple");
|
||||
assertThat(b).isEqualTo("ball");
|
||||
String first = this.environment.getProperty("first.property");
|
||||
String second = this.environment.getProperty("second.property");
|
||||
assertThat(first).isEqualTo("apple");
|
||||
assertThat(second).isEqualTo("ball");
|
||||
}
|
||||
|
||||
private Condition<ConfigurableEnvironment> matchingPropertySource(final String sourceName) {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
first.property=apple
|
|
@ -0,0 +1 @@
|
|||
second.property=ball
|
|
@ -1 +0,0 @@
|
|||
a.property=apple
|
|
@ -1 +0,0 @@
|
|||
b.property=ball
|
Loading…
Reference in New Issue