Ignore placeholder resolution failure as well in case of ignoreResourceNotFound=true

Issue: SPR-11524
This commit is contained in:
Juergen Hoeller 2014-03-07 13:39:01 +01:00
parent 3dfa7e9ac0
commit bcde955ec9
2 changed files with 16 additions and 4 deletions

View File

@ -310,9 +310,9 @@ class ConfigurationClassParser {
throw new IllegalArgumentException("At least one @PropertySource(value) location is required");
}
for (String location : locations) {
Resource resource = this.resourceLoader.getResource(
this.environment.resolveRequiredPlaceholders(location));
try {
Resource resource = this.resourceLoader.getResource(
this.environment.resolveRequiredPlaceholders(location));
if (!StringUtils.hasText(name) || this.propertySources.containsKey(name)) {
// We need to ensure unique names when the property source will
// ultimately end up in a composite
@ -323,7 +323,14 @@ class ConfigurationClassParser {
this.propertySources.add(name, new ResourcePropertySource(name, resource));
}
}
catch (IllegalArgumentException ex) {
// from resolveRequiredPlaceholders
if (!ignoreResourceNotFound) {
throw ex;
}
}
catch (FileNotFoundException ex) {
// from ResourcePropertySource constructor
if (!ignoreResourceNotFound) {
throw ex;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@ -18,12 +18,12 @@ package org.springframework.context.annotation;
import java.io.FileNotFoundException;
import java.util.Iterator;
import javax.inject.Inject;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources;
@ -250,6 +250,7 @@ public class PropertySourceAnnotationTests {
static class ConfigWithNameAndMultipleResourceLocations {
}
@Configuration
@PropertySource(
value = {
@ -268,6 +269,7 @@ public class PropertySourceAnnotationTests {
static class ConfigWithPropertySources {
}
@Configuration
@PropertySources({
@PropertySource(name = "psName", value="classpath:org/springframework/context/annotation/p1.properties"),
@ -282,13 +284,16 @@ public class PropertySourceAnnotationTests {
@PropertySources({
@PropertySource(name = "psName", value="classpath:org/springframework/context/annotation/p1.properties"),
@PropertySource(name = "psName", value="classpath:org/springframework/context/annotation/missing.properties", ignoreResourceNotFound=true),
@PropertySource(name = "psName", value="classpath:${myPath}/missing.properties", ignoreResourceNotFound=true),
@PropertySource(name = "psName", value="classpath:org/springframework/context/annotation/p2.properties")
})
static class ConfigWithIgnoredPropertySource {
}
@Configuration
@PropertySource(value = {})
static class ConfigWithEmptyResourceLocations {
}
}