Refine ignored @PropertySource log warning
If the enclosing environment does not implement ConfigurableEnvironment, then @PropertySource annotations are ignored because there is no way to add them to the Environment. Now checking first to see if there are any @PropertySource annotations present before issuing the warning. Issue: SPR-8314
This commit is contained in:
parent
8190b4f70a
commit
57206db152
|
|
@ -247,17 +247,19 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
|||
parser.validate();
|
||||
|
||||
// Handle any @PropertySource annotations
|
||||
Stack<PropertySource<?>> parsedPropertySources = parser.getPropertySources();
|
||||
if (!parsedPropertySources.isEmpty()) {
|
||||
if (!(this.environment instanceof ConfigurableEnvironment)) {
|
||||
logger.warn("Ignoring @PropertySource annotations. " +
|
||||
"Reason: Environment must implement ConfigurableEnvironment");
|
||||
}
|
||||
else {
|
||||
MutablePropertySources envPropertySources = ((ConfigurableEnvironment)this.environment).getPropertySources();
|
||||
Stack<PropertySource<?>> parsedPropertySources = parser.getPropertySources();
|
||||
while (!parsedPropertySources.isEmpty()) {
|
||||
envPropertySources.addLast(parsedPropertySources.pop());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read the model and create bean definitions based on its content
|
||||
reader.loadBeanDefinitions(parser.getConfigurationClasses());
|
||||
|
|
|
|||
Loading…
Reference in New Issue