diff --git a/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java b/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java index 5b95f6100d3..d914df5ff41 100644 --- a/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java @@ -129,9 +129,9 @@ public class EventListenerMethodProcessor implements SmartInitializingSingleton, */ protected List getEventListenerFactories() { Map beans = getApplicationContext().getBeansOfType(EventListenerFactory.class); - List allFactories = new ArrayList<>(beans.values()); - AnnotationAwareOrderComparator.sort(allFactories); - return allFactories; + List factories = new ArrayList<>(beans.values()); + AnnotationAwareOrderComparator.sort(factories); + return factories; } protected void processBean( @@ -141,9 +141,8 @@ public class EventListenerMethodProcessor implements SmartInitializingSingleton, Map annotatedMethods = null; try { annotatedMethods = MethodIntrospector.selectMethods(targetType, - (MethodIntrospector.MetadataLookup) method -> { - return AnnotatedElementUtils.findMergedAnnotation(method, EventListener.class); - }); + (MethodIntrospector.MetadataLookup) 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. diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java index cf2347c7248..f4d96363df4 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java @@ -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 configurers = + Map beans = ((ListableBeanFactory) this.beanFactory).getBeansOfType(SchedulingConfigurer.class); - for (SchedulingConfigurer configurer : configurers.values()) { + List configurers = new ArrayList<>(beans.values()); + AnnotationAwareOrderComparator.sort(configurers); + for (SchedulingConfigurer configurer : configurers) { configurer.configureTasks(this.registrar); } } diff --git a/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java b/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java index 5c60a650bfc..cac9b4d18e2 100644 --- a/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java +++ b/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java @@ -17,7 +17,9 @@ package org.springframework.jms.annotation; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -41,6 +43,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition; 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.jms.config.JmsListenerConfigUtils; import org.springframework.jms.config.JmsListenerContainerFactory; import org.springframework.jms.config.JmsListenerEndpointRegistrar; @@ -170,9 +173,11 @@ public class JmsListenerAnnotationBeanPostProcessor if (this.beanFactory instanceof ListableBeanFactory) { // Apply JmsListenerConfigurer beans from the BeanFactory, if any - Map instances = + Map beans = ((ListableBeanFactory) this.beanFactory).getBeansOfType(JmsListenerConfigurer.class); - for (JmsListenerConfigurer configurer : instances.values()) { + List configurers = new ArrayList<>(beans.values()); + AnnotationAwareOrderComparator.sort(configurers); + for (JmsListenerConfigurer configurer : configurers) { configurer.configureJmsListeners(this.registrar); } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceUrlProvider.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceUrlProvider.java index b4c3c88d0a3..6a36af764c3 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceUrlProvider.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceUrlProvider.java @@ -18,7 +18,6 @@ package org.springframework.web.reactive.resource; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -106,8 +105,8 @@ public class ResourceUrlProvider implements ApplicationListener map = context.getBeansOfType(SimpleUrlHandlerMapping.class); - List mappings = new ArrayList<>(map.values()); + Map beans = context.getBeansOfType(SimpleUrlHandlerMapping.class); + List mappings = new ArrayList<>(beans.values()); AnnotationAwareOrderComparator.sort(mappings); mappings.forEach(mapping -> { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java index e8d36ad75c2..c3a29e066c8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java @@ -22,7 +22,6 @@ import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; - import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; @@ -142,13 +141,13 @@ public class ResourceUrlProvider implements ApplicationListener map = appContext.getBeansOfType(SimpleUrlHandlerMapping.class); - List handlerMappings = new ArrayList<>(map.values()); - AnnotationAwareOrderComparator.sort(handlerMappings); + Map beans = appContext.getBeansOfType(SimpleUrlHandlerMapping.class); + List mappings = new ArrayList<>(beans.values()); + AnnotationAwareOrderComparator.sort(mappings); - for (SimpleUrlHandlerMapping hm : handlerMappings) { - for (String pattern : hm.getHandlerMap().keySet()) { - Object handler = hm.getHandlerMap().get(pattern); + for (SimpleUrlHandlerMapping mapping : mappings) { + for (String pattern : mapping.getHandlerMap().keySet()) { + Object handler = mapping.getHandlerMap().get(pattern); if (handler instanceof ResourceHttpRequestHandler) { ResourceHttpRequestHandler resourceHandler = (ResourceHttpRequestHandler) handler; if (logger.isDebugEnabled()) {