类 ControllerAdviceBean
- 所有已实现的接口:
cn.taketoday.core.Ordered
@ControllerAdvice
Framework-managed bean without necessarily requiring it to be instantiated.
The findAnnotatedBeans(ApplicationContext, Class...) method can be used to
discover such beans. However, a ControllerAdviceBean may be created
from any object, including ones without an @ControllerAdvice annotation.
- 从以下版本开始:
- 4.0 2022/1/22 21:45
- 作者:
- Rossen Stoyanchev, Brian Clozel, Juergen Hoeller, Sam Brannen, Harry Yang
-
字段概要
字段修饰符和类型字段说明private final cn.taketoday.beans.factory.BeanFactoryprivate final ObjectReference to the actual bean instance or aStringrepresenting the bean name.private final Class<?>private final HandlerTypePredicateprivate final booleanprivate Integerprivate ObjectReference to the resolved bean instance, potentially lazily retrieved via theBeanFactory.从接口继承的字段 cn.taketoday.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
构造器概要
构造器构造器说明ControllerAdviceBean(Object bean) Create aControllerAdviceBeanusing the given bean instance.ControllerAdviceBean(String beanName, cn.taketoday.beans.factory.BeanFactory beanFactory) Create aControllerAdviceBeanusing the given bean name andBeanFactory.ControllerAdviceBean(String beanName, cn.taketoday.beans.factory.BeanFactory beanFactory, ControllerAdvice controllerAdvice) Create aControllerAdviceBeanusing the given bean name,BeanFactory, and@ControllerAdviceannotation.ControllerAdviceBean(String beanName, cn.taketoday.beans.factory.BeanFactory beanFactory, Class<?> beanType, ControllerAdvice controllerAdvice) -
方法概要
修饰符和类型方法说明private static HandlerTypePredicatecreateBeanTypePredicate(ControllerAdvice controllerAdvice) private static HandlerTypePredicatecreateBeanTypePredicate(Class<?> beanType) booleanstatic List<ControllerAdviceBean>findAnnotatedBeans(cn.taketoday.context.ApplicationContext context, Class<?>... types) Find beans annotated with@ControllerAdvicein the givenApplicationContextand wrap them asControllerAdviceBeaninstances.Class<?>Return the type of the contained bean.private static Class<?>getBeanType(String beanName, cn.taketoday.beans.factory.BeanFactory beanFactory) intgetOrder()Get the order value for the contained bean.inthashCode()booleanisApplicableToBeanType(Class<?> beanType) Check whether the given bean type should be advised by thisControllerAdviceBean.(专用程序包) static booleanisCandidate(Class<?> beanType, Class<?>[] types) private cn.taketoday.beans.factory.BeanFactoryGet the bean instance for thisControllerAdviceBean, if necessary resolving the bean name through theBeanFactory.toString()
-
字段详细资料
-
beanOrName
Reference to the actual bean instance or aStringrepresenting the bean name. -
isSingleton
private final boolean isSingleton -
resolvedBean
Reference to the resolved bean instance, potentially lazily retrieved via theBeanFactory. -
beanType
-
beanTypePredicate
-
beanFactory
@Nullable private final cn.taketoday.beans.factory.BeanFactory beanFactory -
order
-
-
构造器详细资料
-
ControllerAdviceBean
Create aControllerAdviceBeanusing the given bean instance.- 参数:
bean- the bean instance
-
ControllerAdviceBean
Create aControllerAdviceBeanusing the given bean name andBeanFactory.- 参数:
beanName- the name of the beanbeanFactory- aBeanFactoryto retrieve the bean type initially and later to resolve the actual bean
-
ControllerAdviceBean
public ControllerAdviceBean(String beanName, cn.taketoday.beans.factory.BeanFactory beanFactory, @Nullable ControllerAdvice controllerAdvice) Create aControllerAdviceBeanusing the given bean name,BeanFactory, and@ControllerAdviceannotation.- 参数:
beanName- the name of the beanbeanFactory- aBeanFactoryto retrieve the bean type initially and later to resolve the actual beancontrollerAdvice- the@ControllerAdviceannotation for the bean, ornullif not yet retrieved
-
ControllerAdviceBean
ControllerAdviceBean(String beanName, cn.taketoday.beans.factory.BeanFactory beanFactory, Class<?> beanType, @Nullable ControllerAdvice controllerAdvice)
-
-
方法详细资料
-
getOrder
public int getOrder()Get the order value for the contained bean.the order value is lazily retrieved using the following algorithm and cached. Note, however, that a
@ControllerAdvicebean that is configured as a scoped bean — for example, as a request-scoped or session-scoped bean — will not be eagerly resolved. Consequently,Orderedis not honored for scoped@ControllerAdvicebeans.- If the resolved bean implements
Ordered, use the value returned byOrdered.getOrder(). - If the factory method
is known, use the value returned by
OrderUtils.getOrder(AnnotatedElement). - If the bean type is known, use the value returned
by
OrderUtils.getOrder(Class, int)withOrdered.LOWEST_PRECEDENCEused as the default order value. - Otherwise use
Ordered.LOWEST_PRECEDENCEas the default, fallback order value.
- 指定者:
getOrder在接口中cn.taketoday.core.Ordered- 另请参阅:
- If the resolved bean implements
-
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
Get the bean instance for thisControllerAdviceBean, if necessary resolving the bean name through theBeanFactory.the bean instance has been resolved it will be cached if it is a singleton, thereby avoiding repeated lookups in the
BeanFactory. -
obtainBeanFactory
private cn.taketoday.beans.factory.BeanFactory obtainBeanFactory() -
isApplicableToBeanType
Check whether the given bean type should be advised by thisControllerAdviceBean.- 参数:
beanType- the type of the bean to check- 另请参阅:
-
equals
-
hashCode
public int hashCode() -
toString
-
findAnnotatedBeans
public static List<ControllerAdviceBean> findAnnotatedBeans(cn.taketoday.context.ApplicationContext context, Class<?>... types) Find beans annotated with@ControllerAdvicein the givenApplicationContextand wrap them asControllerAdviceBeaninstances.the
ControllerAdviceBeaninstances in the returned list are sorted usingOrderComparator.sort(List).- 另请参阅:
-
getOrder()OrderComparatorOrdered
-
isCandidate
-
getBeanType
-
createBeanTypePredicate
-
createBeanTypePredicate
private static HandlerTypePredicate createBeanTypePredicate(@Nullable ControllerAdvice controllerAdvice)
-