ControllerAdvice resolution detects @Order declared on @Bean method as well

Closes gh-25872
This commit is contained in:
Juergen Hoeller
2020-10-12 18:03:39 +02:00
parent 83bfee9201
commit 21f2863d8e
3 changed files with 73 additions and 16 deletions

View File

@@ -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.
@@ -199,7 +199,7 @@ public class ControllerAdviceBeanTests {
}
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public void findAnnotatedBeansSortsBeans() {
Class[] expectedTypes = {
// Since ControllerAdviceBean currently treats PriorityOrdered the same as Ordered,
@@ -208,6 +208,7 @@ public class ControllerAdviceBeanTests {
PriorityOrderedControllerAdvice.class,
OrderAnnotationControllerAdvice.class,
PriorityAnnotationControllerAdvice.class,
SimpleControllerAdviceWithBeanOrder.class,
SimpleControllerAdvice.class,
};
@@ -229,7 +230,7 @@ public class ControllerAdviceBeanTests {
assertThat(new ControllerAdviceBean(bean).getOrder()).isEqualTo(expectedOrder);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"rawtypes", "unchecked"})
private void assertOrder(Class beanType, int expectedOrder) {
String beanName = "myBean";
BeanFactory beanFactory = mock(BeanFactory.class);
@@ -261,6 +262,9 @@ public class ControllerAdviceBeanTests {
@ControllerAdvice
static class SimpleControllerAdvice {}
@ControllerAdvice
static class SimpleControllerAdviceWithBeanOrder {}
@ControllerAdvice
@Order(100)
static class OrderAnnotationControllerAdvice {}
@@ -321,12 +325,12 @@ public class ControllerAdviceBeanTests {
static class MarkerClass {}
@Retention(RetentionPolicy.RUNTIME)
static @interface ControllerAnnotation {}
@interface ControllerAnnotation {}
@ControllerAnnotation
public static class AnnotatedController {}
static interface ControllerInterface {}
interface ControllerInterface {}
static class ImplementationController implements ControllerInterface {}
@@ -342,6 +346,12 @@ public class ControllerAdviceBeanTests {
return new SimpleControllerAdvice();
}
@Bean
@Order(300)
SimpleControllerAdviceWithBeanOrder simpleControllerAdviceWithBeanOrder() {
return new SimpleControllerAdviceWithBeanOrder();
}
@Bean
OrderAnnotationControllerAdvice orderAnnotationControllerAdvice() {
return new OrderAnnotationControllerAdvice();