Ignore placeholder resolution failure as well in case of ignoreResourceNotFound=true
Issue: SPR-11524
This commit is contained in:
parent
3dfa7e9ac0
commit
bcde955ec9
|
@ -310,9 +310,9 @@ class ConfigurationClassParser {
|
||||||
throw new IllegalArgumentException("At least one @PropertySource(value) location is required");
|
throw new IllegalArgumentException("At least one @PropertySource(value) location is required");
|
||||||
}
|
}
|
||||||
for (String location : locations) {
|
for (String location : locations) {
|
||||||
Resource resource = this.resourceLoader.getResource(
|
|
||||||
this.environment.resolveRequiredPlaceholders(location));
|
|
||||||
try {
|
try {
|
||||||
|
Resource resource = this.resourceLoader.getResource(
|
||||||
|
this.environment.resolveRequiredPlaceholders(location));
|
||||||
if (!StringUtils.hasText(name) || this.propertySources.containsKey(name)) {
|
if (!StringUtils.hasText(name) || this.propertySources.containsKey(name)) {
|
||||||
// We need to ensure unique names when the property source will
|
// We need to ensure unique names when the property source will
|
||||||
// ultimately end up in a composite
|
// ultimately end up in a composite
|
||||||
|
@ -323,7 +323,14 @@ class ConfigurationClassParser {
|
||||||
this.propertySources.add(name, new ResourcePropertySource(name, resource));
|
this.propertySources.add(name, new ResourcePropertySource(name, resource));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (IllegalArgumentException ex) {
|
||||||
|
// from resolveRequiredPlaceholders
|
||||||
|
if (!ignoreResourceNotFound) {
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (FileNotFoundException ex) {
|
catch (FileNotFoundException ex) {
|
||||||
|
// from ResourcePropertySource constructor
|
||||||
if (!ignoreResourceNotFound) {
|
if (!ignoreResourceNotFound) {
|
||||||
throw ex;
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.io.FileNotFoundException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.env.MutablePropertySources;
|
import org.springframework.core.env.MutablePropertySources;
|
||||||
|
@ -250,6 +250,7 @@ public class PropertySourceAnnotationTests {
|
||||||
static class ConfigWithNameAndMultipleResourceLocations {
|
static class ConfigWithNameAndMultipleResourceLocations {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@PropertySource(
|
@PropertySource(
|
||||||
value = {
|
value = {
|
||||||
|
@ -268,6 +269,7 @@ public class PropertySourceAnnotationTests {
|
||||||
static class ConfigWithPropertySources {
|
static class ConfigWithPropertySources {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@PropertySources({
|
@PropertySources({
|
||||||
@PropertySource(name = "psName", value="classpath:org/springframework/context/annotation/p1.properties"),
|
@PropertySource(name = "psName", value="classpath:org/springframework/context/annotation/p1.properties"),
|
||||||
|
@ -282,13 +284,16 @@ public class PropertySourceAnnotationTests {
|
||||||
@PropertySources({
|
@PropertySources({
|
||||||
@PropertySource(name = "psName", value="classpath:org/springframework/context/annotation/p1.properties"),
|
@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: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")
|
@PropertySource(name = "psName", value="classpath:org/springframework/context/annotation/p2.properties")
|
||||||
})
|
})
|
||||||
static class ConfigWithIgnoredPropertySource {
|
static class ConfigWithIgnoredPropertySource {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@PropertySource(value = {})
|
@PropertySource(value = {})
|
||||||
static class ConfigWithEmptyResourceLocations {
|
static class ConfigWithEmptyResourceLocations {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue