Skip to content

Commit d1fac36

Browse files
committed
SchedulingConfigurer and JmsListenerConfigurer respect @order
Issue: SPR-16090
1 parent a4537b1 commit d1fac36

File tree

5 files changed

+27
-20
lines changed

5 files changed

+27
-20
lines changed

spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ public void afterSingletonsInstantiated() {
129129
*/
130130
protected List<EventListenerFactory> getEventListenerFactories() {
131131
Map<String, EventListenerFactory> beans = getApplicationContext().getBeansOfType(EventListenerFactory.class);
132-
List<EventListenerFactory> allFactories = new ArrayList<>(beans.values());
133-
AnnotationAwareOrderComparator.sort(allFactories);
134-
return allFactories;
132+
List<EventListenerFactory> factories = new ArrayList<>(beans.values());
133+
AnnotationAwareOrderComparator.sort(factories);
134+
return factories;
135135
}
136136

137137
protected void processBean(
@@ -141,9 +141,8 @@ protected void processBean(
141141
Map<Method, EventListener> annotatedMethods = null;
142142
try {
143143
annotatedMethods = MethodIntrospector.selectMethods(targetType,
144-
(MethodIntrospector.MetadataLookup<EventListener>) method -> {
145-
return AnnotatedElementUtils.findMergedAnnotation(method, EventListener.class);
146-
});
144+
(MethodIntrospector.MetadataLookup<EventListener>) method ->
145+
AnnotatedElementUtils.findMergedAnnotation(method, EventListener.class));
147146
}
148147
catch (Throwable ex) {
149148
// An unresolvable type in a method signature, probably from a lazy bean - let's ignore it.

spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
package org.springframework.scheduling.annotation;
1818

1919
import java.lang.reflect.Method;
20+
import java.util.ArrayList;
2021
import java.util.Collection;
2122
import java.util.Collections;
2223
import java.util.IdentityHashMap;
2324
import java.util.LinkedHashSet;
25+
import java.util.List;
2426
import java.util.Map;
2527
import java.util.Set;
2628
import java.util.TimeZone;
@@ -53,6 +55,7 @@
5355
import org.springframework.core.MethodIntrospector;
5456
import org.springframework.core.Ordered;
5557
import org.springframework.core.annotation.AnnotatedElementUtils;
58+
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
5659
import org.springframework.lang.Nullable;
5760
import org.springframework.scheduling.TaskScheduler;
5861
import org.springframework.scheduling.Trigger;
@@ -211,9 +214,11 @@ private void finishRegistration() {
211214
}
212215

213216
if (this.beanFactory instanceof ListableBeanFactory) {
214-
Map<String, SchedulingConfigurer> configurers =
217+
Map<String, SchedulingConfigurer> beans =
215218
((ListableBeanFactory) this.beanFactory).getBeansOfType(SchedulingConfigurer.class);
216-
for (SchedulingConfigurer configurer : configurers.values()) {
219+
List<SchedulingConfigurer> configurers = new ArrayList<>(beans.values());
220+
AnnotationAwareOrderComparator.sort(configurers);
221+
for (SchedulingConfigurer configurer : configurers) {
217222
configurer.configureTasks(this.registrar);
218223
}
219224
}

spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package org.springframework.jms.annotation;
1818

1919
import java.lang.reflect.Method;
20+
import java.util.ArrayList;
2021
import java.util.Collections;
22+
import java.util.List;
2123
import java.util.Map;
2224
import java.util.Set;
2325
import java.util.concurrent.ConcurrentHashMap;
@@ -41,6 +43,7 @@
4143
import org.springframework.core.MethodIntrospector;
4244
import org.springframework.core.Ordered;
4345
import org.springframework.core.annotation.AnnotatedElementUtils;
46+
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
4447
import org.springframework.jms.config.JmsListenerConfigUtils;
4548
import org.springframework.jms.config.JmsListenerContainerFactory;
4649
import org.springframework.jms.config.JmsListenerEndpointRegistrar;
@@ -170,9 +173,11 @@ public void afterSingletonsInstantiated() {
170173

171174
if (this.beanFactory instanceof ListableBeanFactory) {
172175
// Apply JmsListenerConfigurer beans from the BeanFactory, if any
173-
Map<String, JmsListenerConfigurer> instances =
176+
Map<String, JmsListenerConfigurer> beans =
174177
((ListableBeanFactory) this.beanFactory).getBeansOfType(JmsListenerConfigurer.class);
175-
for (JmsListenerConfigurer configurer : instances.values()) {
178+
List<JmsListenerConfigurer> configurers = new ArrayList<>(beans.values());
179+
AnnotationAwareOrderComparator.sort(configurers);
180+
for (JmsListenerConfigurer configurer : configurers) {
176181
configurer.configureJmsListeners(this.registrar);
177182
}
178183
}

spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceUrlProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.util.ArrayList;
2020
import java.util.Collections;
21-
import java.util.Comparator;
2221
import java.util.LinkedHashMap;
2322
import java.util.List;
2423
import java.util.Map;
@@ -106,8 +105,8 @@ public void onApplicationEvent(ContextRefreshedEvent event) {
106105
private void detectResourceHandlers(ApplicationContext context) {
107106
logger.debug("Looking for resource handler mappings");
108107

109-
Map<String, SimpleUrlHandlerMapping> map = context.getBeansOfType(SimpleUrlHandlerMapping.class);
110-
List<SimpleUrlHandlerMapping> mappings = new ArrayList<>(map.values());
108+
Map<String, SimpleUrlHandlerMapping> beans = context.getBeansOfType(SimpleUrlHandlerMapping.class);
109+
List<SimpleUrlHandlerMapping> mappings = new ArrayList<>(beans.values());
111110
AnnotationAwareOrderComparator.sort(mappings);
112111

113112
mappings.forEach(mapping -> {

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.LinkedHashMap;
2323
import java.util.List;
2424
import java.util.Map;
25-
2625
import javax.servlet.http.HttpServletRequest;
2726

2827
import org.apache.commons.logging.Log;
@@ -142,13 +141,13 @@ public void onApplicationEvent(ContextRefreshedEvent event) {
142141
protected void detectResourceHandlers(ApplicationContext appContext) {
143142
logger.debug("Looking for resource handler mappings");
144143

145-
Map<String, SimpleUrlHandlerMapping> map = appContext.getBeansOfType(SimpleUrlHandlerMapping.class);
146-
List<SimpleUrlHandlerMapping> handlerMappings = new ArrayList<>(map.values());
147-
AnnotationAwareOrderComparator.sort(handlerMappings);
144+
Map<String, SimpleUrlHandlerMapping> beans = appContext.getBeansOfType(SimpleUrlHandlerMapping.class);
145+
List<SimpleUrlHandlerMapping> mappings = new ArrayList<>(beans.values());
146+
AnnotationAwareOrderComparator.sort(mappings);
148147

149-
for (SimpleUrlHandlerMapping hm : handlerMappings) {
150-
for (String pattern : hm.getHandlerMap().keySet()) {
151-
Object handler = hm.getHandlerMap().get(pattern);
148+
for (SimpleUrlHandlerMapping mapping : mappings) {
149+
for (String pattern : mapping.getHandlerMap().keySet()) {
150+
Object handler = mapping.getHandlerMap().get(pattern);
152151
if (handler instanceof ResourceHttpRequestHandler) {
153152
ResourceHttpRequestHandler resourceHandler = (ResourceHttpRequestHandler) handler;
154153
if (logger.isDebugEnabled()) {

0 commit comments

Comments
 (0)