Browse Source

AbstractApplicationEventMulticaster pre-sorts singleton listeners

Issue: SPR-17307

(cherry picked from commit 9063e66c5d)
pull/1998/head
Juergen Hoeller 6 years ago
parent
commit
ca0ce7d631
  1. 15
      spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java

15
spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java

@ -239,7 +239,12 @@ public abstract class AbstractApplicationEventMulticaster @@ -239,7 +239,12 @@ public abstract class AbstractApplicationEventMulticaster
beanFactory.getBean(listenerBeanName, ApplicationListener.class);
if (!allListeners.contains(listener) && supportsEvent(listener, eventType, sourceType)) {
if (retriever != null) {
retriever.applicationListenerBeans.add(listenerBeanName);
if (beanFactory.isSingleton(listenerBeanName)) {
retriever.applicationListeners.add(listener);
}
else {
retriever.applicationListenerBeans.add(listenerBeanName);
}
}
allListeners.add(listener);
}
@ -252,6 +257,10 @@ public abstract class AbstractApplicationEventMulticaster @@ -252,6 +257,10 @@ public abstract class AbstractApplicationEventMulticaster
}
}
AnnotationAwareOrderComparator.sort(allListeners);
if (retriever != null && retriever.applicationListenerBeans.isEmpty()) {
retriever.applicationListeners.clear();
retriever.applicationListeners.addAll(allListeners);
}
return allListeners;
}
@ -385,7 +394,9 @@ public abstract class AbstractApplicationEventMulticaster @@ -385,7 +394,9 @@ public abstract class AbstractApplicationEventMulticaster
}
}
}
AnnotationAwareOrderComparator.sort(allListeners);
if (!this.preFiltered || !this.applicationListenerBeans.isEmpty()) {
AnnotationAwareOrderComparator.sort(allListeners);
}
return allListeners;
}
}

Loading…
Cancel
Save