Package org.springframework.web.method.support

# Class InvocableHandlerMethod

java.lang.Object
org.springframework.core.annotation.AnnotatedMethod
org.springframework.web.method.HandlerMethod
org.springframework.web.method.support.InvocableHandlerMethod

public class InvocableHandlerMethod extends HandlerMethod
Extension of `HandlerMethod` that invokes the underlying method with argument values resolved from the current HTTP request through a list of `HandlerMethodArgumentResolver`.

Since:
  3.1
Author:
  Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze

## Nested Class Summary

## Nested classes/interfaces inherited from class org.springframework.core.annotation.AnnotatedMethod

`org.springframework.core.annotation.AnnotatedMethod.AnnotatedMethodParameter`

## Field Summary

### Fields inherited from class org.springframework.web.method.HandlerMethod

`logger`

## Constructor Summary

Constructors
Modifier
Constructor
Description
``
`InvocableHandlerMethod(Object bean, Method method)`
Create an instance from a bean instance and a method.
`protected`
`InvocableHandlerMethod(Object bean, Method method, org.springframework.context.MessageSource messageSource)`
Variant of `InvocableHandlerMethod(Object, Method)` that also accepts a `MessageSource`, for use in subclasses.
``
`InvocableHandlerMethod(Object bean, String methodName, Class<?>... parameterTypes)`
Construct a new handler method with the given bean instance, method name and parameters.
``
`InvocableHandlerMethod(HandlerMethod handlerMethod)`
Create an instance from a `HandlerMethod`.

## Method Summary

Modifier and Type
Method
Description
`protected Object`
`doInvoke(Object... args)`
Invoke the handler method with the given argument values.
`protected Object[]`
`getMethodArgumentValues(NativeWebRequest request, ModelAndViewContainer mavContainer, Object... providedArgs)`
Get the method argument values for the current request, checking the provided argument values and falling back to the configured argument resolvers.
`Object`
`invokeForRequest(NativeWebRequest request, ModelAndViewContainer mavContainer, Object... providedArgs)`
Invoke the method after resolving its argument values in the context of the given request.
`protected Object`
`invokeSuspendingFunction(Method method, Object target, Object[] args)`
Invoke the given Kotlin coroutine suspended function.
`void`
`setDataBinderFactory(WebDataBinderFactory dataBinderFactory)`
Set the `WebDataBinderFactory` to be passed to argument resolvers allowing them to create a `WebDataBinder` for data binding and type conversion purposes.
`void`
`setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite argumentResolvers)`
Set `HandlerMethodArgumentResolvers` to use for resolving method argument values.
`void`
`setMethodValidator(org.springframework.validation.method.MethodValidator methodValidator)`
Set the `MethodValidator` to perform method validation with if the controller method `HandlerMethod.shouldValidateArguments()` or `HandlerMethod.shouldValidateReturnValue()`.
`void`
`setParameterNameDiscoverer(org.springframework.core.ParameterNameDiscoverer parameterNameDiscoverer)`
Set the ParameterNameDiscoverer for resolving parameter names when needed (for example, default request attribute name).

### Methods inherited from class org.springframework.web.method.HandlerMethod

`assertTargetBean, createWithResolvedBean, createWithValidateFlags, equals, formatInvokeError, getBean, getBeanType, getContainingClass, getResolvedFromHandlerMethod, getResponseStatus, getResponseStatusReason, getShortLogMessage, hashCode, shouldValidateArguments, shouldValidateReturnValue, toString`

### Methods inherited from class org.springframework.core.annotation.AnnotatedMethod

`findProvidedArgument, formatArgumentError, getBridgedMethod, getMethod, getMethodAnnotation, getMethodParameters, getReturnType, getReturnValueType, hasMethodAnnotation, isVoid`

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

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

## Constructor Details

### InvocableHandlerMethod

public InvocableHandlerMethod(HandlerMethod handlerMethod)
Create an instance from a `HandlerMethod`.

### InvocableHandlerMethod

public InvocableHandlerMethod(Object bean, Method method)
Create an instance from a bean instance and a method.

### InvocableHandlerMethod

protected InvocableHandlerMethod(Object bean, Method method, @Nullable org.springframework.context.MessageSource messageSource)
Variant of `InvocableHandlerMethod(Object, Method)` that also accepts a `MessageSource`, for use in subclasses.

Since:
  5.3.10

### InvocableHandlerMethod

public InvocableHandlerMethod(Object bean, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException
Construct a new handler method with the given bean instance, method name and parameters.

Parameters:
  `bean` - the object bean
  `methodName` - the method name
  `parameterTypes` - the method parameter types
Throws:
  `NoSuchMethodException` - when the method cannot be found

## Method Details

### setHandlerMethodArgumentResolvers

public void setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite argumentResolvers)
Set `HandlerMethodArgumentResolvers` to use for resolving method argument values.

### setParameterNameDiscoverer

public void setParameterNameDiscoverer(org.springframework.core.ParameterNameDiscoverer parameterNameDiscoverer)
Set the ParameterNameDiscoverer for resolving parameter names when needed (for example, default request attribute name).

Default is a `DefaultParameterNameDiscoverer`.

### setDataBinderFactory

public void setDataBinderFactory(WebDataBinderFactory dataBinderFactory)
Set the `WebDataBinderFactory` to be passed to argument resolvers allowing them to create a `WebDataBinder` for data binding and type conversion purposes.

### setMethodValidator

public void setMethodValidator(@Nullable org.springframework.validation.method.MethodValidator methodValidator)
Set the `MethodValidator` to perform method validation with if the controller method `HandlerMethod.shouldValidateArguments()` or `HandlerMethod.shouldValidateReturnValue()`.

Since:
  6.1

### invokeForRequest

@Nullable public Object invokeForRequest(NativeWebRequest request, @Nullable ModelAndViewContainer mavContainer, Object... providedArgs) throws Exception
Invoke the method after resolving its argument values in the context of the given request.

Argument values are commonly resolved through `HandlerMethodArgumentResolvers`. The `providedArgs` parameter however may supply argument values to be used directly, i.e. without argument resolution. Examples of provided argument values include a `WebDataBinder`, a `SessionStatus`, or a thrown exception instance. Provided argument values are checked before argument resolvers.

Delegates to `getMethodArgumentValues(org.springframework.web.context.request.NativeWebRequest, org.springframework.web.method.support.ModelAndViewContainer, java.lang.Object...)` and calls `doInvoke(java.lang.Object...)` with the resolved arguments.

Parameters:
  `request` - the current request
  `mavContainer` - the ModelAndViewContainer for this request
  `providedArgs` - "given" arguments matched by type, not resolved
Returns:
  the raw value returned by the invoked method
Throws:
  `Exception` - raised if no suitable argument resolver can be found, or if the method raised an exception
See Also:
  - `getMethodArgumentValues(org.springframework.web.context.request.NativeWebRequest, org.springframework.web.method.support.ModelAndViewContainer, java.lang.Object...)`
  - `doInvoke(java.lang.Object...)`

### getMethodArgumentValues

protected Object[] getMethodArgumentValues(NativeWebRequest request, @Nullable ModelAndViewContainer mavContainer, Object... providedArgs) throws Exception
Get the method argument values for the current request, checking the provided argument values and falling back to the configured argument resolvers.

The resulting array will be passed into `doInvoke(java.lang.Object...)`.

Throws:
  `Exception`
Since:
  5.1.2

### doInvoke

@Nullable protected Object doInvoke(Object... args) throws Exception
Invoke the handler method with the given argument values.

Throws:
  `Exception`

### invokeSuspendingFunction

protected Object invokeSuspendingFunction(Method method, Object target, Object[] args)
Invoke the given Kotlin coroutine suspended function.

The default implementation invokes `CoroutinesUtils.invokeSuspendingFunction(Method, Object, Object...)`, but subclasses can override this method to use `CoroutinesUtils.invokeSuspendingFunction(kotlin.coroutines.CoroutineContext, Method, Object, Object...)` instead.

Since:
  6.0