org.springframework.web.method

## Class HandlerMethod

- java.lang.Object
- - org.springframework.web.method.HandlerMethod

Direct Known Subclasses:
  InvocableHandlerMethod

    public class HandlerMethod
    extends Object

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

The class may be created with a bean instance or with a bean name (e.g. lazy bean, prototype bean). Use `createWithResolvedBean()` to obtain an `HandlerMethod` instance with a bean instance initialized through the bean factory.

Since:
  3.1
Author:
  Arjen Poutsma, Rossen Stoyanchev

### Field Summary

Fields
`protected Log` `logger` Logger that is available to subclasses

### Constructor Summary

Constructors
`protected` `HandlerMethod(HandlerMethod handlerMethod)` Create an instance from another `HandlerMethod`.
`` `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`.

### Method Summary

Methods
`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 o)`
`Object` `getBean()` Returns the bean for this handler method.
`Class<?>` `getBeanType()` 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.
`Method` `getMethod()` Returns the method for this handler method.
`<A extends Annotation> A` `getMethodAnnotation(Class<A> annotationType)` Returns a single annotation on the underlying method traversing its super methods if no annotation can be found on the given method itself.
`MethodParameter[]` `getMethodParameters()` Returns the method parameters for this handler method.
`MethodParameter` `getReturnType()` Return the HandlerMethod return type.
`MethodParameter` `getReturnValueType(Object returnValue)` Return the actual return value type.
`int` `hashCode()`
`boolean` `isVoid()` Returns `true` if the method return type is void, `false` otherwise.
`String` `toString()`

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

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

### Field Detail

#### logger

    protected final Log logger

Logger that is available to subclasses

### 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,
                 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 the bean.

#### HandlerMethod

    protected HandlerMethod(HandlerMethod handlerMethod)

Create an instance from another `HandlerMethod`.

### Method Detail

#### getBean

    public Object getBean()

Returns the bean for this handler method.

#### getMethod

    public Method getMethod()

Returns the method for this handler method.

#### getBeanType

    public Class<?> getBeanType()

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 MethodParameter[] getMethodParameters()

Returns the method parameters for this handler method.

#### getReturnType

    public MethodParameter getReturnType()

Return the HandlerMethod return type.

#### getReturnValueType

    public MethodParameter getReturnValueType(Object returnValue)

Return the actual return value type.

#### isVoid

    public boolean isVoid()

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

#### getMethodAnnotation

    public <A extends Annotation> A getMethodAnnotation(Class<A> annotationType)

Returns a single annotation on the underlying method traversing its super methods if no annotation can be found on the given method itself.

Parameters:
  `annotationType` - the type of annotation to introspect the method for.
Returns:
  the annotation, or `null` if none found

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

#### equals

    public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`