diff --git a/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListener.java b/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListener.java index e720757359..a97c68adf2 100644 --- a/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListener.java +++ b/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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,24 +24,40 @@ import org.springframework.lang.Nullable; /** * Extended variant of the standard {@link ApplicationListener} interface, - * exposing further metadata such as the supported event type. + * exposing further metadata such as the supported event and source type. * - *
As of Spring Framework 4.2, supersedes {@link SmartApplicationListener} with - * proper handling of generics-based event. + *
As of Spring Framework 4.2, this interface supersedes the Class-based
+ * {@link SmartApplicationListener} with full handling of generic event types.
*
* @author Stephane Nicoll
* @since 4.2
+ * @see SmartApplicationListener
+ * @see GenericApplicationListenerAdapter
*/
public interface GenericApplicationListener extends ApplicationListener The default implementation always returns {@code true}.
+ * @param sourceType the source type, or {@code null} if no source
*/
- boolean supportsSourceType(@Nullable Class> sourceType);
+ default boolean supportsSourceType(@Nullable Class> sourceType) {
+ return true;
+ }
+
+ /**
+ * Determine this listener's order in a set of listeners for the same event.
+ * The default implementation returns {@link #LOWEST_PRECEDENCE}.
+ */
+ @Override
+ default int getOrder() {
+ return LOWEST_PRECEDENCE;
+ }
}
diff --git a/spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.java b/spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.java
index 01bb0cbc9f..b66d58878a 100644
--- a/spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.java
+++ b/spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.java
@@ -23,26 +23,40 @@ import org.springframework.lang.Nullable;
/**
* Extended variant of the standard {@link ApplicationListener} interface,
- * exposing further metadata such as the supported event type.
+ * exposing further metadata such as the supported event and source type.
*
- * Users are strongly advised to use the {@link GenericApplicationListener}
- * interface instead as it provides an improved detection of generics-based
- * event types.
+ * For full introspection of generic event types, consider implementing
+ * the {@link GenericApplicationListener} interface instead.
*
* @author Juergen Hoeller
* @since 3.0
* @see GenericApplicationListener
+ * @see GenericApplicationListenerAdapter
*/
public interface SmartApplicationListener extends ApplicationListener The default implementation always returns {@code true}.
+ * @param sourceType the source type, or {@code null} if no source
*/
- boolean supportsSourceType(@Nullable Class> sourceType);
+ default boolean supportsSourceType(@Nullable Class> sourceType) {
+ return true;
+ }
+
+ /**
+ * Determine this listener's order in a set of listeners for the same event.
+ * The default implementation returns {@link #LOWEST_PRECEDENCE}.
+ */
+ @Override
+ default int getOrder() {
+ return LOWEST_PRECEDENCE;
+ }
}