Skip to content

Commit 40f3fb2

Browse files
committed
SchedulingConfigurer and JmsListenerConfigurer respect @order
Issue: SPR-16090
1 parent 268ccb6 commit 40f3fb2

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.springframework.aop.scope.ScopedObject;
3232
import org.springframework.aop.scope.ScopedProxyUtils;
3333
import org.springframework.aop.support.AopUtils;
34-
import org.springframework.beans.BeansException;
3534
import org.springframework.beans.factory.BeanInitializationException;
3635
import org.springframework.beans.factory.SmartInitializingSingleton;
3736
import org.springframework.context.ApplicationContext;
@@ -65,7 +64,7 @@ public class EventListenerMethodProcessor implements SmartInitializingSingleton,
6564

6665

6766
@Override
68-
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
67+
public void setApplicationContext(ApplicationContext applicationContext) {
6968
Assert.isTrue(applicationContext instanceof ConfigurableApplicationContext,
7069
"ApplicationContext does not implement ConfigurableApplicationContext");
7170
this.applicationContext = (ConfigurableApplicationContext) applicationContext;
@@ -119,9 +118,9 @@ public void afterSingletonsInstantiated() {
119118
*/
120119
protected List<EventListenerFactory> getEventListenerFactories() {
121120
Map<String, EventListenerFactory> beans = this.applicationContext.getBeansOfType(EventListenerFactory.class);
122-
List<EventListenerFactory> allFactories = new ArrayList<EventListenerFactory>(beans.values());
123-
AnnotationAwareOrderComparator.sort(allFactories);
124-
return allFactories;
121+
List<EventListenerFactory> factories = new ArrayList<EventListenerFactory>(beans.values());
122+
AnnotationAwareOrderComparator.sort(factories);
123+
return factories;
125124
}
126125

127126
protected void processBean(final List<EventListenerFactory> factories, final String beanName, final Class<?> targetType) {

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

+7-2
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.scheduling.TaskScheduler;
5760
import org.springframework.scheduling.Trigger;
5861
import org.springframework.scheduling.config.CronTask;
@@ -207,9 +210,11 @@ private void finishRegistration() {
207210
}
208211

209212
if (this.beanFactory instanceof ListableBeanFactory) {
210-
Map<String, SchedulingConfigurer> configurers =
213+
Map<String, SchedulingConfigurer> beans =
211214
((ListableBeanFactory) this.beanFactory).getBeansOfType(SchedulingConfigurer.class);
212-
for (SchedulingConfigurer configurer : configurers.values()) {
215+
List<SchedulingConfigurer> configurers = new ArrayList<SchedulingConfigurer>(beans.values());
216+
AnnotationAwareOrderComparator.sort(configurers);
217+
for (SchedulingConfigurer configurer : configurers) {
213218
configurer.configureTasks(this.registrar);
214219
}
215220
}

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

+7-2
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;
@@ -166,9 +169,11 @@ public void afterSingletonsInstantiated() {
166169

167170
if (this.beanFactory instanceof ListableBeanFactory) {
168171
// Apply JmsListenerConfigurer beans from the BeanFactory, if any
169-
Map<String, JmsListenerConfigurer> instances =
172+
Map<String, JmsListenerConfigurer> beans =
170173
((ListableBeanFactory) this.beanFactory).getBeansOfType(JmsListenerConfigurer.class);
171-
for (JmsListenerConfigurer configurer : instances.values()) {
174+
List<JmsListenerConfigurer> configurers = new ArrayList<JmsListenerConfigurer>(beans.values());
175+
AnnotationAwareOrderComparator.sort(configurers);
176+
for (JmsListenerConfigurer configurer : configurers) {
172177
configurer.configureJmsListeners(this.registrar);
173178
}
174179
}

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -148,13 +148,13 @@ public void onApplicationEvent(ContextRefreshedEvent event) {
148148
protected void detectResourceHandlers(ApplicationContext appContext) {
149149
logger.debug("Looking for resource handler mappings");
150150

151-
Map<String, SimpleUrlHandlerMapping> map = appContext.getBeansOfType(SimpleUrlHandlerMapping.class);
152-
List<SimpleUrlHandlerMapping> handlerMappings = new ArrayList<SimpleUrlHandlerMapping>(map.values());
153-
AnnotationAwareOrderComparator.sort(handlerMappings);
151+
Map<String, SimpleUrlHandlerMapping> beans = appContext.getBeansOfType(SimpleUrlHandlerMapping.class);
152+
List<SimpleUrlHandlerMapping> mappings = new ArrayList<SimpleUrlHandlerMapping>(beans.values());
153+
AnnotationAwareOrderComparator.sort(mappings);
154154

155-
for (SimpleUrlHandlerMapping hm : handlerMappings) {
156-
for (String pattern : hm.getHandlerMap().keySet()) {
157-
Object handler = hm.getHandlerMap().get(pattern);
155+
for (SimpleUrlHandlerMapping mapping : mappings) {
156+
for (String pattern : mapping.getHandlerMap().keySet()) {
157+
Object handler = mapping.getHandlerMap().get(pattern);
158158
if (handler instanceof ResourceHttpRequestHandler) {
159159
ResourceHttpRequestHandler resourceHandler = (ResourceHttpRequestHandler) handler;
160160
if (logger.isDebugEnabled()) {

0 commit comments

Comments
 (0)