org.springframework.web.method

## Class ControllerAdviceBean

- java.lang.Object
- - org.springframework.web.method.ControllerAdviceBean

- All Implemented Interfaces:
    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, an `ControllerAdviceBean` may be created from any object, including ones without an `@ControllerAdvice`.

  Since:
    3.2
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    - ### Fields inherited from interface org.springframework.core.Ordered

      `HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ControllerAdviceBean(Object bean)` Create an instance using the given bean instance.
    `ControllerAdviceBean(String beanName, BeanFactory beanFactory)` Create an instance using the given bean name.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object o)`
    `static List<ControllerAdviceBean>` | `findAnnotatedBeans(ApplicationContext applicationContext)` Find the names of beans annotated with @ControllerAdvice in the given ApplicationContext and wrap them as `ControllerAdviceBean` instances.
    `Class<?>` | `getBeanType()` Returns the type of the contained bean.
    `int` | `getOrder()` Returns the order value extracted from the `ControllerAdvice` annotation or `Ordered.LOWEST_PRECEDENCE` otherwise.
    `int` | `hashCode()`
    `Object` | `resolveBean()` Return a bean instance if necessary resolving the bean name through the BeanFactory.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ControllerAdviceBean

          public ControllerAdviceBean(String beanName,
                              BeanFactory beanFactory)

      Create an instance using the given bean name.
      Parameters:
        `beanName` - the name of the bean
        `beanFactory` - a BeanFactory that can be used later to resolve the bean

    - #### ControllerAdviceBean

          public ControllerAdviceBean(Object bean)

      Create an instance using the given bean instance.
      Parameters:
        `bean` - the bean

  - ### Method Detail

    - #### findAnnotatedBeans

          public static List<ControllerAdviceBean> findAnnotatedBeans(ApplicationContext applicationContext)

      Find the names of beans annotated with @ControllerAdvice in the given ApplicationContext and wrap them as `ControllerAdviceBean` instances.

    - #### getOrder

          public int getOrder()

      Returns the order value extracted from the `ControllerAdvice` annotation or `Ordered.LOWEST_PRECEDENCE` otherwise.
      Specified by:
        `getOrder` in interface `Ordered`
      Returns:
        the order value

    - #### getBeanType

          public Class<?> getBeanType()

      Returns 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()

      Return a bean instance if necessary resolving the bean name through the BeanFactory.

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`