Class ControllerAdviceBean
- All Implemented Interfaces:
- 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.
- Since:
- 3.2
- Author:
- Rossen Stoyanchev, Brian Clozel, Juergen Hoeller, Sam Brannen
- 
Field SummaryFields inherited from interface org.springframework.core.OrderedHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
- 
Constructor SummaryConstructorsConstructorDescriptionControllerAdviceBean(Object bean) Create aControllerAdviceBeanusing the given bean instance.ControllerAdviceBean(String beanName, BeanFactory beanFactory) Create aControllerAdviceBeanusing the given bean name andBeanFactory.ControllerAdviceBean(String beanName, BeanFactory beanFactory, ControllerAdvice controllerAdvice) Create aControllerAdviceBeanusing the given bean name,BeanFactory, and@ControllerAdviceannotation.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanstatic List<ControllerAdviceBean>findAnnotatedBeans(ApplicationContext context) Find beans annotated with@ControllerAdvicein the givenApplicationContextand wrap them asControllerAdviceBeaninstances.Class<?>Return the type of the contained bean.intgetOrder()Get the order value for the contained bean.inthashCode()booleanisApplicableToBeanType(Class<?> beanType) Check whether the given bean type should be advised by thisControllerAdviceBean.Get the bean instance for thisControllerAdviceBean, if necessary resolving the bean name through theBeanFactory.toString()
- 
Constructor Details- 
ControllerAdviceBeanCreate aControllerAdviceBeanusing the given bean instance.- Parameters:
- bean- the bean instance
 
- 
ControllerAdviceBeanCreate aControllerAdviceBeanusing the given bean name andBeanFactory.- Parameters:
- beanName- the name of the bean
- beanFactory- a- BeanFactoryto retrieve the bean type initially and later to resolve the actual bean
 
- 
ControllerAdviceBeanpublic ControllerAdviceBean(String beanName, BeanFactory beanFactory, @Nullable ControllerAdvice controllerAdvice) Create aControllerAdviceBeanusing the given bean name,BeanFactory, and@ControllerAdviceannotation.- Parameters:
- beanName- the name of the bean
- beanFactory- a- BeanFactoryto retrieve the bean type initially and later to resolve the actual bean
- controllerAdvice- the- @ControllerAdviceannotation for the bean, or- nullif not yet retrieved
- Since:
- 5.2
 
 
- 
- 
Method Details- 
getOrderpublic int getOrder()Get the order value for the contained bean.As of Spring Framework 5.3, 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.
 
- If the resolved bean implements 
- 
getBeanTypeReturn the type of the contained bean.If the bean type is a CGLIB-generated class, the original user-defined class is returned. 
- 
resolveBeanGet 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.
- 
isApplicableToBeanTypeCheck whether the given bean type should be advised by thisControllerAdviceBean.- Parameters:
- beanType- the type of the bean to check
- Since:
- 4.0
- See Also:
 
- 
equals
- 
hashCodepublic int hashCode()
- 
toString
- 
findAnnotatedBeansFind beans annotated with@ControllerAdvicein the givenApplicationContextand wrap them asControllerAdviceBeaninstances.As of Spring Framework 5.2, the ControllerAdviceBeaninstances in the returned list are sorted usingOrderComparator.sort(List).- See Also:
 
 
-