Package 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, aControllerAdviceBeanmay be created from any object, including ones without an@ControllerAdvice.- Since:
- 3.2
- Author:
- Rossen Stoyanchev, Brian Clozel, Juergen Hoeller
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor Summary
Constructors Constructor Description ControllerAdviceBean(Object bean)Create aControllerAdviceBeanusing the given bean instance.ControllerAdviceBean(String beanName, BeanFactory beanFactory)Create aControllerAdviceBeanusing the given bean name.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object other)static List<ControllerAdviceBean>findAnnotatedBeans(ApplicationContext applicationContext)Find the names of beans annotated with @ControllerAdvice in the given ApplicationContext and wrap them asControllerAdviceBeaninstances.Class<?>getBeanType()Return the type of the contained bean.intgetOrder()Returns the order value extracted from theControllerAdviceannotation, orOrdered.LOWEST_PRECEDENCEotherwise.inthashCode()booleanisApplicableToBeanType(Class<?> beanType)Check whether the given bean type should be assisted by this@ControllerAdviceinstance.ObjectresolveBean()Return a bean instance if necessary resolving the bean name through the BeanFactory.StringtoString()
Constructor Detail
ControllerAdviceBean
public ControllerAdviceBean(Object bean)
Create aControllerAdviceBeanusing the given bean instance.- Parameters:
bean- the bean instance
ControllerAdviceBean
public ControllerAdviceBean(String beanName, BeanFactory beanFactory)
Create aControllerAdviceBeanusing the given bean name.- Parameters:
beanName- the name of the beanbeanFactory- a BeanFactory that can be used later to resolve the bean
Method Detail
getOrder
public int getOrder()
Returns the order value extracted from theControllerAdviceannotation, orOrdered.LOWEST_PRECEDENCEotherwise.- Specified by:
getOrderin interfaceOrdered- Returns:
- the order value
- See Also:
Ordered.HIGHEST_PRECEDENCE,Ordered.LOWEST_PRECEDENCE
getBeanType
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()
Return a bean instance if necessary resolving the bean name through the BeanFactory.
isApplicableToBeanType
public boolean isApplicableToBeanType(Class<?> beanType)
Check whether the given bean type should be assisted by this@ControllerAdviceinstance.- Parameters:
beanType- the type of the bean to check- Since:
- 4.0
- See Also:
ControllerAdvice
findAnnotatedBeans
public static List<ControllerAdviceBean> findAnnotatedBeans(ApplicationContext applicationContext)
Find the names of beans annotated with @ControllerAdvice in the given ApplicationContext and wrap them asControllerAdviceBeaninstances.