public class HandlerMethod extends Object
The class may be created with a bean instance or with a bean name
(e.g. lazy-init bean, prototype bean). Use createWithResolvedBean()
to obtain a HandlerMethod
instance with a bean instance resolved
through the associated BeanFactory
.
Modifier and Type | Class and Description |
---|---|
protected class |
HandlerMethod.HandlerMethodParameter
A MethodParameter with HandlerMethod-specific behavior.
|
Modifier and Type | Field and Description |
---|---|
static Log |
defaultLogger
Public for wrapping with fallback logger.
|
protected Log |
logger |
Modifier | Constructor and Description |
---|---|
protected |
HandlerMethod(HandlerMethod handlerMethod)
Copy constructor for use in subclasses.
|
|
HandlerMethod(Object bean,
Method method)
Create an instance from a bean instance and a method.
|
|
HandlerMethod(Object bean,
String methodName,
Class<?>... parameterTypes)
Create an instance from a bean instance, method name, and parameter types.
|
|
HandlerMethod(String beanName,
BeanFactory beanFactory,
Method method)
Create an instance from a bean name, a method, and a
BeanFactory . |
Modifier and Type | Method and Description |
---|---|
protected void |
assertTargetBean(Method method,
Object targetBean,
Object[] args)
Assert that the target bean class is an instance of the class where the given
method is declared.
|
HandlerMethod |
createWithResolvedBean()
If the provided instance contains a bean name rather than an object instance,
the bean name is resolved before a
HandlerMethod is created and returned. |
boolean |
equals(Object other) |
protected static Object |
findProvidedArgument(MethodParameter parameter,
Object... providedArgs) |
protected static String |
formatArgumentError(MethodParameter param,
String message) |
protected String |
formatInvokeError(String text,
Object[] args) |
Object |
getBean()
Return the bean for this handler method.
|
Class<?> |
getBeanType()
This method returns the type of the handler for this handler method.
|
protected Method |
getBridgedMethod()
If the bean method is a bridge method, this method returns the bridged
(user-defined) method.
|
Log |
getLogger()
Return the currently configured Logger.
|
Method |
getMethod()
Return the method for this handler method.
|
<A extends Annotation> |
getMethodAnnotation(Class<A> annotationType)
Return a single annotation on the underlying method traversing its super methods
if no annotation can be found on the given method itself.
|
MethodParameter[] |
getMethodParameters()
Return the method parameters for this handler method.
|
HandlerMethod |
getResolvedFromHandlerMethod()
Return the HandlerMethod from which this HandlerMethod instance was
resolved via
createWithResolvedBean() . |
MethodParameter |
getReturnType()
Return the HandlerMethod return type.
|
MethodParameter |
getReturnValueType(Object returnValue)
Return the actual return value type.
|
String |
getShortLogMessage()
Return a short representation of this handler method for log message purposes.
|
int |
hashCode() |
<A extends Annotation> |
hasMethodAnnotation(Class<A> annotationType)
Return whether the parameter is declared with the given annotation type.
|
boolean |
isVoid()
Return
true if the method return type is void, false otherwise. |
void |
setLogger(Log logger)
Set an alternative logger to use than the one based on the class name.
|
String |
toString() |
public static final Log defaultLogger
protected Log logger
public HandlerMethod(Object bean, Method method)
public HandlerMethod(Object bean, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException
NoSuchMethodException
- when the method cannot be foundpublic HandlerMethod(String beanName, BeanFactory beanFactory, Method method)
BeanFactory
.
The method createWithResolvedBean()
may be used later to
re-create the HandlerMethod
with an initialized bean.protected HandlerMethod(HandlerMethod handlerMethod)
public void setLogger(Log logger)
logger
- the logger to usepublic Log getLogger()
public Object getBean()
public Method getMethod()
public Class<?> getBeanType()
Note that if the bean type is a CGLIB-generated class, the original user-defined class is returned.
protected Method getBridgedMethod()
getMethod()
.public MethodParameter[] getMethodParameters()
public MethodParameter getReturnType()
public MethodParameter getReturnValueType(@Nullable Object returnValue)
public boolean isVoid()
true
if the method return type is void, false
otherwise.@Nullable public <A extends Annotation> A getMethodAnnotation(Class<A> annotationType)
Also supports merged composed annotations with attribute overrides as of Spring Framework 4.3.
annotationType
- the type of annotation to introspect the method fornull
if none foundAnnotatedElementUtils.findMergedAnnotation(java.lang.reflect.AnnotatedElement, java.lang.Class<A>)
public <A extends Annotation> boolean hasMethodAnnotation(Class<A> annotationType)
annotationType
- the annotation type to look forAnnotatedElementUtils.hasAnnotation(java.lang.reflect.AnnotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation>)
@Nullable public HandlerMethod getResolvedFromHandlerMethod()
createWithResolvedBean()
.public HandlerMethod createWithResolvedBean()
HandlerMethod
is created and returned.public String getShortLogMessage()
@Nullable protected static Object findProvidedArgument(MethodParameter parameter, @Nullable Object... providedArgs)
protected static String formatArgumentError(MethodParameter param, String message)
protected void assertTargetBean(Method method, Object targetBean, Object[] args)