public class ControllerAdviceBean extends Object implements Ordered
@ControllerAdvice
Spring-managed bean without necessarily requiring it to be instantiated.
The findAnnotatedBeans(ApplicationContext)
method can be used to
discover such beans. However, a ControllerAdviceBean
may be created
from any object, including ones without an @ControllerAdvice
annotation.
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
ControllerAdviceBean(Object bean)
Create a
ControllerAdviceBean using the given bean instance. |
ControllerAdviceBean(String beanName,
BeanFactory beanFactory)
Create a
ControllerAdviceBean using the given bean name and
BeanFactory . |
ControllerAdviceBean(String beanName,
BeanFactory beanFactory,
ControllerAdvice controllerAdvice)
Create a
ControllerAdviceBean using the given bean name,
BeanFactory , and @ControllerAdvice
annotation. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
static List<ControllerAdviceBean> |
findAnnotatedBeans(ApplicationContext context)
Find beans annotated with
@ControllerAdvice in the
given ApplicationContext and wrap them as ControllerAdviceBean
instances. |
Class<?> |
getBeanType()
Return the type of the contained bean.
|
int |
getOrder()
Get the order value for the contained bean.
|
int |
hashCode() |
boolean |
isApplicableToBeanType(Class<?> beanType)
Check whether the given bean type should be advised by this
ControllerAdviceBean . |
Object |
resolveBean()
Get the bean instance for this
ControllerAdviceBean , if necessary
resolving the bean name through the BeanFactory . |
String |
toString() |
public ControllerAdviceBean(Object bean)
ControllerAdviceBean
using the given bean instance.bean
- the bean instancepublic ControllerAdviceBean(String beanName, BeanFactory beanFactory)
ControllerAdviceBean
using the given bean name and
BeanFactory
.beanName
- the name of the beanbeanFactory
- a BeanFactory
to retrieve the bean type initially
and later to resolve the actual beanpublic ControllerAdviceBean(String beanName, BeanFactory beanFactory, @Nullable ControllerAdvice controllerAdvice)
ControllerAdviceBean
using the given bean name,
BeanFactory
, and @ControllerAdvice
annotation.beanName
- the name of the beanbeanFactory
- a BeanFactory
to retrieve the bean type initially
and later to resolve the actual beancontrollerAdvice
- the @ControllerAdvice
annotation for the
bean, or null
if not yet retrievedpublic int getOrder()
As of Spring Framework 5.2, the order value is lazily retrieved using
the following algorithm and cached. Note, however, that a
@ControllerAdvice
bean that is configured as a
scoped bean — for example, as a request-scoped or session-scoped
bean — will not be eagerly resolved. Consequently, Ordered
is
not honored for scoped @ControllerAdvice
beans.
Ordered
,
use the value returned by Ordered.getOrder()
.OrderUtils.getOrder(Class, int)
with Ordered.LOWEST_PRECEDENCE
used as the default order value.Ordered.LOWEST_PRECEDENCE
as the default, fallback
order value.getOrder
in interface Ordered
resolveBean()
@Nullable public Class<?> getBeanType()
If the bean type is a CGLIB-generated class, the original user-defined class is returned.
public Object resolveBean()
ControllerAdviceBean
, if necessary
resolving the bean name through the BeanFactory
.
As of Spring Framework 5.2, once the bean instance has been resolved it
will be cached, thereby avoiding repeated lookups in the BeanFactory
.
public boolean isApplicableToBeanType(@Nullable Class<?> beanType)
ControllerAdviceBean
.beanType
- the type of the bean to checkControllerAdvice
public static List<ControllerAdviceBean> findAnnotatedBeans(ApplicationContext context)
@ControllerAdvice
in the
given ApplicationContext
and wrap them as ControllerAdviceBean
instances.
As of Spring Framework 5.2, the ControllerAdviceBean
instances
in the returned list are sorted using OrderComparator.sort(List)
.
getOrder()
,
OrderComparator
,
Ordered