diff --git a/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java index 494f4c886e1..25acbc84816 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -81,7 +81,19 @@ public abstract class OrderUtils { */ @Nullable public static Integer getOrder(Class type) { - return getOrderFromAnnotations(type, MergedAnnotations.from(type, SearchStrategy.TYPE_HIERARCHY)); + return getOrder((AnnotatedElement) type); + } + + /** + * Return the order declared on the specified {@code element}. + *

Takes care of {@link Order @Order} and {@code @javax.annotation.Priority}. + * @param element the annotated element (e.g. type or method) + * @return the order value, or {@code null} if none can be found + * @since 5.3 + */ + @Nullable + public static Integer getOrder(AnnotatedElement element) { + return getOrderFromAnnotations(element, MergedAnnotations.from(element, SearchStrategy.TYPE_HIERARCHY)); } /** diff --git a/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java b/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java index 21846840809..b8e2436d516 100644 --- a/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java +++ b/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java @@ -16,13 +16,21 @@ package org.springframework.web.method; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import org.springframework.aop.scope.ScopedProxyUtils; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryUtils; +import org.springframework.beans.factory.ListableBeanFactory; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.OrderComparator; import org.springframework.core.Ordered; import org.springframework.core.annotation.AnnotatedElementUtils; @@ -128,7 +136,7 @@ public class ControllerAdviceBean implements Ordered { /** * Get the order value for the contained bean. - *

As of Spring Framework 5.2, the order value is lazily retrieved using + *

As of Spring Framework 5.3, the order value is lazily retrieved using * the following algorithm and cached. Note, however, that a * {@link ControllerAdvice @ControllerAdvice} bean that is configured as a * scoped bean — for example, as a request-scoped or session-scoped @@ -137,6 +145,8 @@ public class ControllerAdviceBean implements Ordered { *