SchedulingConfigurer and JmsListenerConfigurer respect @Order

Issue: SPR-16090
This commit is contained in:
Juergen Hoeller
2017-10-20 16:10:12 +02:00
parent a4537b1b6d
commit d1fac36e3e
5 changed files with 27 additions and 20 deletions

View File

@@ -129,9 +129,9 @@ public class EventListenerMethodProcessor implements SmartInitializingSingleton,
*/
protected List<EventListenerFactory> getEventListenerFactories() {
Map<String, EventListenerFactory> beans = getApplicationContext().getBeansOfType(EventListenerFactory.class);
List<EventListenerFactory> allFactories = new ArrayList<>(beans.values());
AnnotationAwareOrderComparator.sort(allFactories);
return allFactories;
List<EventListenerFactory> factories = new ArrayList<>(beans.values());
AnnotationAwareOrderComparator.sort(factories);
return factories;
}
protected void processBean(
@@ -141,9 +141,8 @@ public class EventListenerMethodProcessor implements SmartInitializingSingleton,
Map<Method, EventListener> annotatedMethods = null;
try {
annotatedMethods = MethodIntrospector.selectMethods(targetType,
(MethodIntrospector.MetadataLookup<EventListener>) method -> {
return AnnotatedElementUtils.findMergedAnnotation(method, EventListener.class);
});
(MethodIntrospector.MetadataLookup<EventListener>) method ->
AnnotatedElementUtils.findMergedAnnotation(method, EventListener.class));
}
catch (Throwable ex) {
// An unresolvable type in a method signature, probably from a lazy bean - let's ignore it.

View File

@@ -17,10 +17,12 @@
package org.springframework.scheduling.annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
@@ -53,6 +55,7 @@ import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.MethodIntrospector;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.Trigger;
@@ -211,9 +214,11 @@ public class ScheduledAnnotationBeanPostProcessor
}
if (this.beanFactory instanceof ListableBeanFactory) {
Map<String, SchedulingConfigurer> configurers =
Map<String, SchedulingConfigurer> beans =
((ListableBeanFactory) this.beanFactory).getBeansOfType(SchedulingConfigurer.class);
for (SchedulingConfigurer configurer : configurers.values()) {
List<SchedulingConfigurer> configurers = new ArrayList<>(beans.values());
AnnotationAwareOrderComparator.sort(configurers);
for (SchedulingConfigurer configurer : configurers) {
configurer.configureTasks(this.registrar);
}
}