类 ControllerAdviceBean
- java.lang.Object
- org.springframework.web.method.ControllerAdviceBean
- 所有已实现的接口:
Ordered
public class ControllerAdviceBean extends Object implements Ordered
Encapsulates information about an@ControllerAdvice
Spring-managed bean without necessarily requiring it to be instantiated.The
findAnnotatedBeans(ApplicationContext)
method can be used to discover such beans. However, aControllerAdviceBean
may be created from any object, including ones without an@ControllerAdvice
annotation.- 从以下版本开始:
- 3.2
- 作者:
- Rossen Stoyanchev, Brian Clozel, Juergen Hoeller, Sam Brannen
字段概要
从接口继承的字段 org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
构造器概要
构造器 构造器 说明 ControllerAdviceBean(Object bean)
Create aControllerAdviceBean
using the given bean instance.ControllerAdviceBean(String beanName, BeanFactory beanFactory)
Create aControllerAdviceBean
using the given bean name andBeanFactory
.ControllerAdviceBean(String beanName, BeanFactory beanFactory, ControllerAdvice controllerAdvice)
Create aControllerAdviceBean
using the given bean name,BeanFactory
, and@ControllerAdvice
annotation.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 boolean
equals(Object other)
static List<ControllerAdviceBean>
findAnnotatedBeans(ApplicationContext context)
Find beans annotated with@ControllerAdvice
in the givenApplicationContext
and wrap them asControllerAdviceBean
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 thisControllerAdviceBean
.Object
resolveBean()
Get the bean instance for thisControllerAdviceBean
, if necessary resolving the bean name through theBeanFactory
.String
toString()
构造器详细资料
ControllerAdviceBean
public ControllerAdviceBean(Object bean)
Create aControllerAdviceBean
using the given bean instance.- 参数:
bean
- the bean instance
ControllerAdviceBean
public ControllerAdviceBean(String beanName, BeanFactory beanFactory)
Create aControllerAdviceBean
using the given bean name andBeanFactory
.- 参数:
beanName
- the name of the beanbeanFactory
- aBeanFactory
to retrieve the bean type initially and later to resolve the actual bean
ControllerAdviceBean
public ControllerAdviceBean(String beanName, BeanFactory beanFactory, @Nullable ControllerAdvice controllerAdvice)
Create aControllerAdviceBean
using the given bean name,BeanFactory
, and@ControllerAdvice
annotation.- 参数:
beanName
- the name of the beanbeanFactory
- aBeanFactory
to retrieve the bean type initially and later to resolve the actual beancontrollerAdvice
- the@ControllerAdvice
annotation for the bean, ornull
if not yet retrieved- 从以下版本开始:
- 5.2
方法详细资料
getOrder
public int getOrder()
Get the order value for the contained bean.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.- If the resolved bean implements
Ordered
, use the value returned byOrdered.getOrder()
. - If the bean type is known, use the value returned by
OrderUtils.getOrder(Class, int)
withOrdered.LOWEST_PRECEDENCE
used as the default order value. - Otherwise use
Ordered.LOWEST_PRECEDENCE
as the default, fallback order value.
- 指定者:
getOrder
在接口中Ordered
- 返回:
- the order value
- 另请参阅:
resolveBean()
- If the resolved bean implements
getBeanType
@Nullable public Class<?> getBeanType()
Return the type of the contained bean.If the bean type is a CGLIB-generated class, the original user-defined class is returned.
resolveBean
public Object resolveBean()
Get the bean instance for thisControllerAdviceBean
, if necessary resolving the bean name through theBeanFactory
.As of Spring Framework 5.2, once the bean instance has been resolved it will be cached if it is a singleton, thereby avoiding repeated lookups in the
BeanFactory
.
isApplicableToBeanType
public boolean isApplicableToBeanType(@Nullable Class<?> beanType)
Check whether the given bean type should be advised by thisControllerAdviceBean
.- 参数:
beanType
- the type of the bean to check- 从以下版本开始:
- 4.0
- 另请参阅:
ControllerAdvice
findAnnotatedBeans
public static List<ControllerAdviceBean> findAnnotatedBeans(ApplicationContext context)
Find beans annotated with@ControllerAdvice
in the givenApplicationContext
and wrap them asControllerAdviceBean
instances.As of Spring Framework 5.2, the
ControllerAdviceBean
instances in the returned list are sorted usingOrderComparator.sort(List)
.- 另请参阅:
getOrder()
,OrderComparator
,Ordered