Skip to content

Commit d64ac32

Browse files
committed
ControllerAdviceBean accepts bean types without @ControllerAdvice annotation (as in 3.2)
Issue: SPR-13759
1 parent 415b92b commit d64ac32

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.lang.annotation.Annotation;
2020
import java.util.ArrayList;
2121
import java.util.Arrays;
22+
import java.util.Collections;
2223
import java.util.LinkedHashSet;
2324
import java.util.List;
2425
import java.util.Set;
@@ -102,13 +103,16 @@ private ControllerAdviceBean(Object bean, BeanFactory beanFactory) {
102103
}
103104

104105
ControllerAdvice annotation = AnnotationUtils.findAnnotation(beanType, ControllerAdvice.class);
105-
if (annotation == null) {
106-
throw new IllegalArgumentException(
107-
"Bean type [" + beanType.getName() + "] is not annotated as @ControllerAdvice");
106+
if (annotation != null) {
107+
this.basePackages = initBasePackages(annotation);
108+
this.assignableTypes = Arrays.asList(annotation.assignableTypes());
109+
this.annotations = Arrays.asList(annotation.annotations());
110+
}
111+
else {
112+
this.basePackages = Collections.emptySet();
113+
this.assignableTypes = Collections.emptyList();
114+
this.annotations = Collections.emptyList();
108115
}
109-
this.basePackages = initBasePackages(annotation);
110-
this.assignableTypes = Arrays.asList(annotation.assignableTypes());
111-
this.annotations = Arrays.asList(annotation.annotations());
112116
}
113117

114118

0 commit comments

Comments
 (0)