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, aControllerAdviceBean
may 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 aControllerAdviceBean
using the given bean instance.ControllerAdviceBean(String beanName, BeanFactory beanFactory)
Create aControllerAdviceBean
using the given bean name.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object other)
static List<ControllerAdviceBean>
findAnnotatedBeans(ApplicationContext applicationContext)
Find the names of beans annotated with @ControllerAdvice in the given ApplicationContext and wrap them asControllerAdviceBean
instances.Class<?>
getBeanType()
Return the type of the contained bean.int
getOrder()
Returns the order value extracted from theControllerAdvice
annotation, orOrdered.LOWEST_PRECEDENCE
otherwise.int
hashCode()
boolean
isApplicableToBeanType(Class<?> beanType)
Check whether the given bean type should be assisted by this@ControllerAdvice
instance.Object
resolveBean()
Return a bean instance if necessary resolving the bean name through the BeanFactory.String
toString()
Constructor Detail
ControllerAdviceBean
public ControllerAdviceBean(Object bean)
Create aControllerAdviceBean
using the given bean instance.- Parameters:
bean
- the bean instance
ControllerAdviceBean
public ControllerAdviceBean(String beanName, BeanFactory beanFactory)
Create aControllerAdviceBean
using 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 theControllerAdvice
annotation, orOrdered.LOWEST_PRECEDENCE
otherwise.- Specified by:
getOrder
in 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@ControllerAdvice
instance.- 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 asControllerAdviceBean
instances.