From 2b0b4a58cb747e88f21e781f9f9663eb6cc21be0 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Thu, 12 May 2011 12:27:14 +0000 Subject: [PATCH] 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 git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4295 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../ConfigurationClassPostProcessor.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) 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()); + } } }