类 ControllerAdviceBean

java.lang.Object
cn.taketoday.web.handler.method.ControllerAdviceBean
所有已实现的接口:
cn.taketoday.core.Ordered

public class ControllerAdviceBean extends Object implements cn.taketoday.core.Ordered
Encapsulates information about an @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
  • 字段详细资料

    • beanOrName

      private final Object beanOrName
      Reference to the actual bean instance or a String representing the bean name.
    • isSingleton

      private final boolean isSingleton
    • resolvedBean

      @Nullable private Object resolvedBean
      Reference to the resolved bean instance, potentially lazily retrieved via the BeanFactory.
    • beanType

      @Nullable private final Class<?> beanType
    • beanTypePredicate

      private final HandlerTypePredicate beanTypePredicate
    • beanFactory

      @Nullable private final cn.taketoday.beans.factory.BeanFactory beanFactory
    • order

      @Nullable private Integer order
  • 构造器详细资料

    • ControllerAdviceBean

      public ControllerAdviceBean(Object bean)
      Create a ControllerAdviceBean using the given bean instance.
      参数:
      bean - the bean instance
    • ControllerAdviceBean

      public ControllerAdviceBean(String beanName, cn.taketoday.beans.factory.BeanFactory beanFactory)
      Create a ControllerAdviceBean using the given bean name and BeanFactory.
      参数:
      beanName - the name of the bean
      beanFactory - a BeanFactory to 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 a ControllerAdviceBean using the given bean name, BeanFactory, and @ControllerAdvice annotation.
      参数:
      beanName - the name of the bean
      beanFactory - a BeanFactory to retrieve the bean type initially and later to resolve the actual bean
      controllerAdvice - the @ControllerAdvice annotation for the bean, or null if 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 @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 by Ordered.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) with Ordered.LOWEST_PRECEDENCE used as the default order value.
      • Otherwise use Ordered.LOWEST_PRECEDENCE as the default, fallback order value.
      指定者:
      getOrder 在接口中 cn.taketoday.core.Ordered
      另请参阅:
    • 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 this ControllerAdviceBean, if necessary resolving the bean name through the BeanFactory.

      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

      public boolean isApplicableToBeanType(@Nullable Class<?> beanType)
      Check whether the given bean type should be advised by this ControllerAdviceBean.
      参数:
      beanType - the type of the bean to check
      另请参阅:
    • equals

      public boolean equals(@Nullable Object other)
      覆盖:
      equals 在类中 Object
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 Object
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object
    • findAnnotatedBeans

      public static List<ControllerAdviceBean> findAnnotatedBeans(cn.taketoday.context.ApplicationContext context, Class<?>... types)
      Find beans annotated with @ControllerAdvice in the given ApplicationContext and wrap them as ControllerAdviceBean instances.

      the ControllerAdviceBean instances in the returned list are sorted using OrderComparator.sort(List).

      另请参阅:
    • isCandidate

      static boolean isCandidate(@Nullable Class<?> beanType, @Nullable Class<?>[] types)
    • getBeanType

      @Nullable private static Class<?> getBeanType(String beanName, cn.taketoday.beans.factory.BeanFactory beanFactory)
    • createBeanTypePredicate

      private static HandlerTypePredicate createBeanTypePredicate(@Nullable Class<?> beanType)
    • createBeanTypePredicate

      private static HandlerTypePredicate createBeanTypePredicate(@Nullable ControllerAdvice controllerAdvice)