From e21d8042adb2db1244a00b83029ee7734b7983cd Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 27 Mar 2015 17:13:25 +0100 Subject: [PATCH] Upgrade event listener to GenericApplicationListener SmartApplicationListener has been superseded by GenericEventListener as of Spring Framework 4.2. It will be eventually deprecated and removed. Migrate our event listeners to use the new contract. Closes gh-2576 --- .../AutoConfigurationReportLoggingInitializer.java | 10 ++++++---- .../logging/ClasspathLoggingApplicationListener.java | 9 ++++++--- .../boot/logging/LoggingApplicationListener.java | 8 +++++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializer.java index 9ece748811..ce5ce2fb3d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,9 +35,10 @@ import org.springframework.context.ApplicationEvent; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.event.ApplicationContextEvent; import org.springframework.context.event.ContextRefreshedEvent; -import org.springframework.context.event.SmartApplicationListener; +import org.springframework.context.event.GenericApplicationListener; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.Ordered; +import org.springframework.core.ResolvableType; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -178,7 +179,7 @@ public class AutoConfigurationReportLoggingInitializer implements } - private class AutoConfigurationReportListener implements SmartApplicationListener { + private class AutoConfigurationReportListener implements GenericApplicationListener { @Override public int getOrder() { @@ -186,7 +187,8 @@ public class AutoConfigurationReportLoggingInitializer implements } @Override - public boolean supportsEventType(Class type) { + public boolean supportsEventType(ResolvableType resolvableType) { + Class type = resolvableType.getRawClass(); return ContextRefreshedEvent.class.isAssignableFrom(type) || ApplicationFailedEvent.class.isAssignableFrom(type); } diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/ClasspathLoggingApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/logging/ClasspathLoggingApplicationListener.java index a6d0908be4..65971f96f9 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/ClasspathLoggingApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/ClasspathLoggingApplicationListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,10 @@ import org.apache.commons.logging.LogFactory; import org.springframework.boot.context.event.ApplicationFailedEvent; import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.context.ApplicationEvent; +import org.springframework.context.event.GenericApplicationListener; import org.springframework.context.event.SmartApplicationListener; import org.springframework.core.Ordered; +import org.springframework.core.ResolvableType; /** * A {@link SmartApplicationListener} that reacts to {@link ApplicationStartedEvent start @@ -36,7 +38,7 @@ import org.springframework.core.Ordered; * @author Andy Wilkinson */ public final class ClasspathLoggingApplicationListener implements - SmartApplicationListener { + GenericApplicationListener { private static final int ORDER = Ordered.HIGHEST_PRECEDENCE + 12; @@ -64,7 +66,8 @@ public final class ClasspathLoggingApplicationListener implements } @Override - public boolean supportsEventType(Class type) { + public boolean supportsEventType(ResolvableType resolvableType) { + Class type = resolvableType.getRawClass(); return ApplicationStartedEvent.class.isAssignableFrom(type) || ApplicationFailedEvent.class.isAssignableFrom(type); } diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java index f62a040a49..aef6b5e702 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java @@ -31,8 +31,9 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextClosedEvent; -import org.springframework.context.event.SmartApplicationListener; +import org.springframework.context.event.GenericApplicationListener; import org.springframework.core.Ordered; +import org.springframework.core.ResolvableType; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; import org.springframework.util.LinkedMultiValueMap; @@ -61,7 +62,7 @@ import org.springframework.util.StringUtils; * @author Andy Wilkinson * @see LoggingSystem#get(ClassLoader) */ -public class LoggingApplicationListener implements SmartApplicationListener { +public class LoggingApplicationListener implements GenericApplicationListener { /** * The name of the Spring property that contains a reference to the logging @@ -115,7 +116,8 @@ public class LoggingApplicationListener implements SmartApplicationListener { private LogLevel springBootLogging = null; @Override - public boolean supportsEventType(Class eventType) { + public boolean supportsEventType(ResolvableType resolvableType) { + Class eventType = resolvableType.getRawClass(); return isAssignableFrom(eventType, EVENT_TYPES); }