ControllerAdviceBean accepts bean types without @ControllerAdvice annotation (as in 3.2)

Issue: SPR-13759
(cherry picked from commit d64ac32)
This commit is contained in:
Juergen Hoeller
2015-12-04 13:03:00 +01:00
parent 7a7877040f
commit 6963e27c7a

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -19,6 +19,7 @@ package org.springframework.web.method;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -102,13 +103,16 @@ public class ControllerAdviceBean implements Ordered {
}
ControllerAdvice annotation = AnnotationUtils.findAnnotation(beanType, ControllerAdvice.class);
if (annotation == null) {
throw new IllegalArgumentException(
"Bean type [" + beanType.getName() + "] is not annotated as @ControllerAdvice");
if (annotation != null) {
this.basePackages = initBasePackages(annotation);
this.assignableTypes = Arrays.asList(annotation.assignableTypes());
this.annotations = Arrays.asList(annotation.annotations());
}
else {
this.basePackages = Collections.emptySet();
this.assignableTypes = Collections.emptyList();
this.annotations = Collections.emptyList();
}
this.basePackages = initBasePackages(annotation);
this.assignableTypes = Arrays.asList(annotation.assignableTypes());
this.annotations = Arrays.asList(annotation.annotations());
}