diff --git a/org.springframework.context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java b/org.springframework.context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java index b94a4d1fb40..055e5aef741 100644 --- a/org.springframework.context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java +++ b/org.springframework.context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java @@ -247,15 +247,17 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo parser.validate(); // Handle any @PropertySource annotations - if (!(this.environment instanceof ConfigurableEnvironment)) { - logger.warn("Ignoring @PropertySource annotations. " + - "Reason: Environment must implement ConfigurableEnvironment"); - } - else { - MutablePropertySources envPropertySources = ((ConfigurableEnvironment)this.environment).getPropertySources(); - Stack> parsedPropertySources = parser.getPropertySources(); - while (!parsedPropertySources.isEmpty()) { - envPropertySources.addLast(parsedPropertySources.pop()); + Stack> 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(); + while (!parsedPropertySources.isEmpty()) { + envPropertySources.addLast(parsedPropertySources.pop()); + } } }