Commit e21d8042 authored by Stephane Nicoll's avatar Stephane Nicoll

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
parent f5023fd4
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -35,9 +35,10 @@ import org.springframework.context.ApplicationEvent; ...@@ -35,9 +35,10 @@ import org.springframework.context.ApplicationEvent;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.event.ApplicationContextEvent; import org.springframework.context.event.ApplicationContextEvent;
import org.springframework.context.event.ContextRefreshedEvent; 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.context.support.GenericApplicationContext;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.ResolvableType;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
...@@ -178,7 +179,7 @@ public class AutoConfigurationReportLoggingInitializer implements ...@@ -178,7 +179,7 @@ public class AutoConfigurationReportLoggingInitializer implements
} }
private class AutoConfigurationReportListener implements SmartApplicationListener { private class AutoConfigurationReportListener implements GenericApplicationListener {
@Override @Override
public int getOrder() { public int getOrder() {
...@@ -186,7 +187,8 @@ public class AutoConfigurationReportLoggingInitializer implements ...@@ -186,7 +187,8 @@ public class AutoConfigurationReportLoggingInitializer implements
} }
@Override @Override
public boolean supportsEventType(Class<? extends ApplicationEvent> type) { public boolean supportsEventType(ResolvableType resolvableType) {
Class<?> type = resolvableType.getRawClass();
return ContextRefreshedEvent.class.isAssignableFrom(type) return ContextRefreshedEvent.class.isAssignableFrom(type)
|| ApplicationFailedEvent.class.isAssignableFrom(type); || ApplicationFailedEvent.class.isAssignableFrom(type);
} }
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -24,8 +24,10 @@ import org.apache.commons.logging.LogFactory; ...@@ -24,8 +24,10 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.boot.context.event.ApplicationFailedEvent; import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.GenericApplicationListener;
import org.springframework.context.event.SmartApplicationListener; import org.springframework.context.event.SmartApplicationListener;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.ResolvableType;
/** /**
* A {@link SmartApplicationListener} that reacts to {@link ApplicationStartedEvent start * A {@link SmartApplicationListener} that reacts to {@link ApplicationStartedEvent start
...@@ -36,7 +38,7 @@ import org.springframework.core.Ordered; ...@@ -36,7 +38,7 @@ import org.springframework.core.Ordered;
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
public final class ClasspathLoggingApplicationListener implements public final class ClasspathLoggingApplicationListener implements
SmartApplicationListener { GenericApplicationListener {
private static final int ORDER = Ordered.HIGHEST_PRECEDENCE + 12; private static final int ORDER = Ordered.HIGHEST_PRECEDENCE + 12;
...@@ -64,7 +66,8 @@ public final class ClasspathLoggingApplicationListener implements ...@@ -64,7 +66,8 @@ public final class ClasspathLoggingApplicationListener implements
} }
@Override @Override
public boolean supportsEventType(Class<? extends ApplicationEvent> type) { public boolean supportsEventType(ResolvableType resolvableType) {
Class<?> type = resolvableType.getRawClass();
return ApplicationStartedEvent.class.isAssignableFrom(type) return ApplicationStartedEvent.class.isAssignableFrom(type)
|| ApplicationFailedEvent.class.isAssignableFrom(type); || ApplicationFailedEvent.class.isAssignableFrom(type);
} }
......
...@@ -31,8 +31,9 @@ import org.springframework.context.ApplicationContext; ...@@ -31,8 +31,9 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent; 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.Ordered;
import org.springframework.core.ResolvableType;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
...@@ -61,7 +62,7 @@ import org.springframework.util.StringUtils; ...@@ -61,7 +62,7 @@ import org.springframework.util.StringUtils;
* @author Andy Wilkinson * @author Andy Wilkinson
* @see LoggingSystem#get(ClassLoader) * @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 * The name of the Spring property that contains a reference to the logging
...@@ -115,7 +116,8 @@ public class LoggingApplicationListener implements SmartApplicationListener { ...@@ -115,7 +116,8 @@ public class LoggingApplicationListener implements SmartApplicationListener {
private LogLevel springBootLogging = null; private LogLevel springBootLogging = null;
@Override @Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) { public boolean supportsEventType(ResolvableType resolvableType) {
Class<?> eventType = resolvableType.getRawClass();
return isAssignableFrom(eventType, EVENT_TYPES); return isAssignableFrom(eventType, EVENT_TYPES);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment