Skip to content

Presort beans in ControllerAdviceBean.findAnnotatedBeans() #23188

@sbrannen

Description

@sbrannen

Status Quo

The findAnnotatedBeans(ApplicationContext) static utility method in ControllerAdviceBean currently does not sort the list it returns. However, every use case within the Spring Framework currently sorts the returned list immediately -- for example, in ControllerMethodResolver.initControllerAdviceCaches(ApplicationContext) (WebFlux), ExceptionHandlerExceptionResolver.initExceptionHandlerAdviceCache() (Web MVC), etc.

Since every known use case needs the beans sorted, we should just sort them upfront.

In addition, the current clients of this utility method sort the beans using AnnotationAwareOrderComparator which adds unnecessary overhead since a ControllerAdviceBean is never annotated with @Order or @Priority: @Order or @Priority are already honored internally in ControllerAdviceBean#getOrder(). We should therefore only sort ControllerAdviceBean instances using OrderComparator.

Deliverables

  • Sort ControllerAdviceBean instances using OrderComparator directly within ControllerAdviceBean.findAnnotatedBeans().

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions