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

Issue: SPR-11524
master
Juergen Hoeller 11 years ago
parent 3dfa7e9ac0
commit bcde955ec9
  1. 9
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
  2. 9
      spring-context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java

@ -310,9 +310,9 @@ class ConfigurationClassParser {
throw new IllegalArgumentException("At least one @PropertySource(value) location is required");
}
for (String location : locations) {
try {
Resource resource = this.resourceLoader.getResource(
this.environment.resolveRequiredPlaceholders(location));
try {
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;
}

@ -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 {
}
}

Loading…
Cancel
Save