Skip to content

Commit 6963e27

Browse files
committed
ControllerAdviceBean accepts bean types without @ControllerAdvice annotation (as in 3.2)
Issue: SPR-13759 (cherry picked from commit d64ac32)
1 parent 7a78770 commit 6963e27

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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)