From d26857289cb346be81f56cde9205347d1f15e752 Mon Sep 17 00:00:00 2001 From: satamas Date: Thu, 29 Jun 2017 00:22:48 +0300 Subject: [PATCH 1/2] Narrow the event types ConfigFileApplicationListener supports See gh-9628 --- .../config/ConfigFileApplicationListener.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java index 9748cbf39b0..29690963379 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java @@ -46,9 +46,9 @@ import org.springframework.boot.env.EnvironmentPostProcessor; import org.springframework.boot.env.PropertySourcesLoader; import org.springframework.boot.logging.DeferredLog; import org.springframework.context.ApplicationEvent; -import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.ConfigurationClassPostProcessor; +import org.springframework.context.event.SmartApplicationListener; import org.springframework.core.Ordered; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.convert.ConversionService; @@ -62,6 +62,7 @@ import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.support.SpringFactoriesLoader; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; @@ -102,7 +103,7 @@ import org.springframework.validation.BindException; * @author EddĂș MelĂ©ndez */ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, - ApplicationListener, Ordered { + SmartApplicationListener, Ordered { private static final String DEFAULT_PROPERTIES = "defaultProperties"; @@ -276,6 +277,17 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, this.names = names; } + @Override + public boolean supportsEventType(Class eventType) { + return ApplicationEnvironmentPreparedEvent.class.isAssignableFrom(eventType) || + ApplicationPreparedEvent.class.isAssignableFrom(eventType); + } + + @Override + public boolean supportsSourceType(@Nullable Class aClass) { + return true; + } + /** * {@link BeanFactoryPostProcessor} to re-order our property sources below any * {@code @PropertySource} items added by the {@link ConfigurationClassPostProcessor}. From 26b27d41e749e7ddc8d926ef7dca4a94ff8eae3d Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 29 Jun 2017 09:57:41 +0200 Subject: [PATCH 2/2] Polish "Narrow the event types ConfigFileApplicationListener supports" Closes gh-9628 --- .../config/ConfigFileApplicationListener.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java index 29690963379..1776bac9dc6 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java @@ -62,7 +62,6 @@ import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.support.SpringFactoriesLoader; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; @@ -152,6 +151,17 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, private final ConversionService conversionService = new DefaultConversionService(); + @Override + public boolean supportsEventType(Class eventType) { + return ApplicationEnvironmentPreparedEvent.class.isAssignableFrom(eventType) || + ApplicationPreparedEvent.class.isAssignableFrom(eventType); + } + + @Override + public boolean supportsSourceType(Class aClass) { + return true; + } + @Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ApplicationEnvironmentPreparedEvent) { @@ -277,17 +287,6 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, this.names = names; } - @Override - public boolean supportsEventType(Class eventType) { - return ApplicationEnvironmentPreparedEvent.class.isAssignableFrom(eventType) || - ApplicationPreparedEvent.class.isAssignableFrom(eventType); - } - - @Override - public boolean supportsSourceType(@Nullable Class aClass) { - return true; - } - /** * {@link BeanFactoryPostProcessor} to re-order our property sources below any * {@code @PropertySource} items added by the {@link ConfigurationClassPostProcessor}.