Presort beans in ControllerAdviceBean.findAnnotatedBeans()

Prior to this commit, all clients of
ControllerAdviceBean.findAnnotatedBeans() sorted the returned list
manually. In addition, clients within the core Spring Framework
unnecessarily used AnnotationAwareOrderComparator instead of
OrderComparator to sort the list.

This commit presorts the ControllerAdviceBean list using OrderComparator
directly within ControllerAdviceBean.findAnnotatedBeans().

Closes gh-23188
This commit is contained in:
Sam Brannen
2019-06-24 14:48:18 +03:00
parent dd15ff79d7
commit d0231cb29a
7 changed files with 96 additions and 32 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.lang.Nullable;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.SubscribableChannel;
@@ -62,14 +61,10 @@ public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMetho
logger.trace("Looking for @MessageExceptionHandler mappings: " + context);
}
List<ControllerAdviceBean> beans = ControllerAdviceBean.findAnnotatedBeans(context);
AnnotationAwareOrderComparator.sort(beans);
initMessagingAdviceCache(MessagingControllerAdviceBean.createFromList(beans));
}
private void initMessagingAdviceCache(@Nullable List<MessagingAdviceBean> beans) {
if (beans == null) {
return;
}
private void initMessagingAdviceCache(List<MessagingAdviceBean> beans) {
for (MessagingAdviceBean bean : beans) {
Class<?> type = bean.getBeanType();
if (type != null) {