Browse Source

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

Issue: SPR-13759
(cherry picked from commit d64ac32)
pull/931/head
Juergen Hoeller 10 years ago
parent
commit
6963e27c7a
  1. 18
      spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java

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

@ -1,5 +1,5 @@ @@ -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; @@ -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 { @@ -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());
}

Loading…
Cancel
Save