public class ControllerAdviceBean extends java.lang.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.
Modifier and Type | Field and Description |
---|---|
private java.lang.Object |
bean |
private BeanFactory |
beanFactory |
private HandlerTypePredicate |
beanTypePredicate |
private int |
order |
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Modifier | Constructor and Description |
---|---|
|
ControllerAdviceBean(java.lang.Object bean)
Create a
ControllerAdviceBean using the given bean instance. |
private |
ControllerAdviceBean(java.lang.Object bean,
BeanFactory beanFactory) |
|
ControllerAdviceBean(java.lang.String beanName,
BeanFactory beanFactory)
Create a
ControllerAdviceBean using the given bean name. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object other) |
static java.util.List<ControllerAdviceBean> |
findAnnotatedBeans(ApplicationContext context)
Find beans annotated with
@ControllerAdvice in the
given ApplicationContext and wrap them as ControllerAdviceBean
instances. |
java.lang.Class<?> |
getBeanType()
Return the type of the contained bean.
|
int |
getOrder()
Return the order value extracted from the
ControllerAdvice
annotation, or Ordered.LOWEST_PRECEDENCE otherwise. |
int |
hashCode() |
private static int |
initOrderFromBean(java.lang.Object bean) |
private static int |
initOrderFromBeanType(java.lang.Class<?> beanType) |
boolean |
isApplicableToBeanType(java.lang.Class<?> beanType)
Check whether the given bean type should be advised by this
ControllerAdviceBean . |
private BeanFactory |
obtainBeanFactory() |
java.lang.Object |
resolveBean()
Return a bean instance if necessary resolving the bean name through the BeanFactory.
|
java.lang.String |
toString() |
private final java.lang.Object bean
@Nullable private final BeanFactory beanFactory
private final int order
private final HandlerTypePredicate beanTypePredicate
public ControllerAdviceBean(java.lang.Object bean)
ControllerAdviceBean
using the given bean instance.bean
- the bean instancepublic ControllerAdviceBean(java.lang.String beanName, @Nullable BeanFactory beanFactory)
ControllerAdviceBean
using the given bean name.beanName
- the name of the beanbeanFactory
- a BeanFactory that can be used later to resolve the beanprivate ControllerAdviceBean(java.lang.Object bean, @Nullable BeanFactory beanFactory)
public int getOrder()
ControllerAdvice
annotation, or Ordered.LOWEST_PRECEDENCE
otherwise.getOrder
in interface Ordered
Ordered.HIGHEST_PRECEDENCE
,
Ordered.LOWEST_PRECEDENCE
@Nullable public java.lang.Class<?> getBeanType()
If the bean type is a CGLIB-generated class, the original user-defined class is returned.
public java.lang.Object resolveBean()
private BeanFactory obtainBeanFactory()
public boolean isApplicableToBeanType(@Nullable java.lang.Class<?> beanType)
ControllerAdviceBean
.beanType
- the type of the bean to checkControllerAdvice
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public static java.util.List<ControllerAdviceBean> findAnnotatedBeans(ApplicationContext context)
@ControllerAdvice
in the
given ApplicationContext
and wrap them as ControllerAdviceBean
instances.private static int initOrderFromBean(java.lang.Object bean)
private static int initOrderFromBeanType(@Nullable java.lang.Class<?> beanType)