org.springframework.messaging.handler

## Class HandlerMethod

- java.lang.Object
- - org.springframework.messaging.handler.HandlerMethod

Direct Known Subclasses:
  InvocableHandlerMethod, InvocableHandlerMethod

    public class HandlerMethod
    extends Object

Encapsulates information about a handler method consisting of a method and a bean. Provides convenient access to method parameters, the method return value, method annotations, etc.

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`.

Since:
  4.0
Author:
  Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller

### Nested Class Summary

Nested Classes
`protected class` `HandlerMethod.HandlerMethodParameter` A MethodParameter with HandlerMethod-specific behavior.

### Field Summary

Fields
`static Log` `defaultLogger` Public for wrapping with fallback logger.
`protected Log` `logger`

### Constructor Summary

Constructors
`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, org.springframework.beans.factory.BeanFactory beanFactory, Method method)` Create an instance from a bean name, a method, and a `BeanFactory`.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`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(org.springframework.core.MethodParameter parameter, Object... providedArgs)`
`protected static String` `formatArgumentError(org.springframework.core.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> A` `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.
`org.springframework.core.MethodParameter[]` `getMethodParameters()` Return the method parameters for this handler method.
`HandlerMethod` `getResolvedFromHandlerMethod()` Return the HandlerMethod from which this HandlerMethod instance was resolved via `createWithResolvedBean()`.
`org.springframework.core.MethodParameter` `getReturnType()` Return the HandlerMethod return type.
`org.springframework.core.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> boolean` `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()`

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

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

### Field Detail

#### defaultLogger

    public static final Log defaultLogger

Public for wrapping with fallback logger.

#### logger

    protected Log logger

### Constructor Detail

#### HandlerMethod

    public HandlerMethod(Object bean,
                         Method method)

Create an instance from a bean instance and a method.

#### HandlerMethod

    public HandlerMethod(Object bean,
                         String methodName,
                         Class<?>... parameterTypes)
                  throws NoSuchMethodException

Create an instance from a bean instance, method name, and parameter types.

Throws:
  `NoSuchMethodException` - when the method cannot be found

#### HandlerMethod

    public HandlerMethod(String beanName,
                         org.springframework.beans.factory.BeanFactory beanFactory,
                         Method method)

Create an instance from a bean name, a method, and a `BeanFactory`. The method `createWithResolvedBean()` may be used later to re-create the `HandlerMethod` with an initialized bean.

#### HandlerMethod

    protected HandlerMethod(HandlerMethod handlerMethod)

Copy constructor for use in subclasses.

### Method Detail

#### setLogger

    public void setLogger(Log logger)

Set an alternative logger to use than the one based on the class name.

Parameters:
  `logger` - the logger to use
Since:
  5.1

#### getLogger

    public Log getLogger()

Return the currently configured Logger.

Since:
  5.1

#### getBean

    public Object getBean()

Return the bean for this handler method.

#### getMethod

    public Method getMethod()

Return the method for this handler method.

#### getBeanType

    public Class<?> getBeanType()

This method returns the type of the handler for this handler method.

Note that if the bean type is a CGLIB-generated class, the original user-defined class is returned.

#### getBridgedMethod

    protected Method getBridgedMethod()

If the bean method is a bridge method, this method returns the bridged (user-defined) method. Otherwise it returns the same method as `getMethod()`.

#### getMethodParameters

    public org.springframework.core.MethodParameter[] getMethodParameters()

Return the method parameters for this handler method.

#### getReturnType

    public org.springframework.core.MethodParameter getReturnType()

Return the HandlerMethod return type.

#### getReturnValueType

    public org.springframework.core.MethodParameter getReturnValueType(@Nullable
                                                                       Object returnValue)

Return the actual return value type.

#### isVoid

    public boolean isVoid()

Return `true` if the method return type is void, `false` otherwise.

#### getMethodAnnotation

    @Nullable
    public <A extends Annotation> A 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.

Also supports merged composed annotations with attribute overrides as of Spring Framework 4.3.

Parameters:
  `annotationType` - the type of annotation to introspect the method for
Returns:
  the annotation, or `null` if none found
See Also:
  `AnnotatedElementUtils.findMergedAnnotation(java.lang.reflect.AnnotatedElement, java.lang.Class<A>)`

#### hasMethodAnnotation

    public <A extends Annotation> boolean hasMethodAnnotation(Class<A> annotationType)

Return whether the parameter is declared with the given annotation type.

Parameters:
  `annotationType` - the annotation type to look for
Since:
  4.3
See Also:
  `AnnotatedElementUtils.hasAnnotation(java.lang.reflect.AnnotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation>)`

#### getResolvedFromHandlerMethod

    @Nullable
    public HandlerMethod getResolvedFromHandlerMethod()

Return the HandlerMethod from which this HandlerMethod instance was resolved via `createWithResolvedBean()`.

Since:
  4.3

#### createWithResolvedBean

    public 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.

#### getShortLogMessage

    public String getShortLogMessage()

Return a short representation of this handler method for log message purposes.

#### equals

    public boolean equals(@Nullable
                          Object other)

Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### findProvidedArgument

    @Nullable
    protected static Object findProvidedArgument(org.springframework.core.MethodParameter parameter,
                                                           @Nullable
                                                           Object... providedArgs)

#### formatArgumentError

    protected static String formatArgumentError(org.springframework.core.MethodParameter param,
                                                String message)

#### assertTargetBean

    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. In some cases the actual endpoint instance at request- processing time may be a JDK dynamic proxy (lazy initialization, prototype beans, and others). Endpoint classes that require proxying should prefer class-based proxy mechanisms.

#### formatInvokeError

    protected String formatInvokeError(String text,
                                       Object[] args)