Skip to content

Commit d268572

Browse files
satamassnicoll
authored andcommitted
Narrow the event types ConfigFileApplicationListener supports
See gh-9628
1 parent eb299b9 commit d268572

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
import org.springframework.boot.env.PropertySourcesLoader;
4747
import org.springframework.boot.logging.DeferredLog;
4848
import org.springframework.context.ApplicationEvent;
49-
import org.springframework.context.ApplicationListener;
5049
import org.springframework.context.ConfigurableApplicationContext;
5150
import org.springframework.context.annotation.ConfigurationClassPostProcessor;
51+
import org.springframework.context.event.SmartApplicationListener;
5252
import org.springframework.core.Ordered;
5353
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
5454
import org.springframework.core.convert.ConversionService;
@@ -62,6 +62,7 @@
6262
import org.springframework.core.io.Resource;
6363
import org.springframework.core.io.ResourceLoader;
6464
import org.springframework.core.io.support.SpringFactoriesLoader;
65+
import org.springframework.lang.Nullable;
6566
import org.springframework.util.Assert;
6667
import org.springframework.util.ResourceUtils;
6768
import org.springframework.util.StringUtils;
@@ -102,7 +103,7 @@
102103
* @author Eddú Meléndez
103104
*/
104105
public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
105-
ApplicationListener<ApplicationEvent>, Ordered {
106+
SmartApplicationListener, Ordered {
106107

107108
private static final String DEFAULT_PROPERTIES = "defaultProperties";
108109

@@ -276,6 +277,17 @@ public void setSearchNames(String names) {
276277
this.names = names;
277278
}
278279

280+
@Override
281+
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
282+
return ApplicationEnvironmentPreparedEvent.class.isAssignableFrom(eventType) ||
283+
ApplicationPreparedEvent.class.isAssignableFrom(eventType);
284+
}
285+
286+
@Override
287+
public boolean supportsSourceType(@Nullable Class<?> aClass) {
288+
return true;
289+
}
290+
279291
/**
280292
* {@link BeanFactoryPostProcessor} to re-order our property sources below any
281293
* {@code @PropertySource} items added by the {@link ConfigurationClassPostProcessor}.

0 commit comments

Comments
 (0)