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
pull/2657/merge
Stephane Nicoll 10 years ago
parent f5023fd415
commit e21d8042ad

@ -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<? extends ApplicationEvent> type) {
public boolean supportsEventType(ResolvableType resolvableType) {
Class<?> type = resolvableType.getRawClass();
return ContextRefreshedEvent.class.isAssignableFrom(type)
|| ApplicationFailedEvent.class.isAssignableFrom(type);
}

@ -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<? extends ApplicationEvent> type) {
public boolean supportsEventType(ResolvableType resolvableType) {
Class<?> type = resolvableType.getRawClass();
return ApplicationStartedEvent.class.isAssignableFrom(type)
|| ApplicationFailedEvent.class.isAssignableFrom(type);
}

@ -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<? extends ApplicationEvent> eventType) {
public boolean supportsEventType(ResolvableType resolvableType) {
Class<?> eventType = resolvableType.getRawClass();
return isAssignableFrom(eventType, EVENT_TYPES);
}

Loading…
Cancel
Save