Class HandlerMethod
- Direct Known Subclasses:
InvocableHandlerMethod
,InvocableHandlerMethod
,SyncInvocableHandlerMethod
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:
- 3.1
- Author:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Sam Brannen
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
A MethodParameter with HandlerMethod-specific behavior. -
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionHandlerMethod
(Object bean, Method method) Create an instance from a bean instance and a method.protected
HandlerMethod
(Object bean, Method method, MessageSource messageSource) Variant ofHandlerMethod(Object, Method)
that also accepts aMessageSource
for use from subclasses.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 aBeanFactory
.HandlerMethod
(String beanName, BeanFactory beanFactory, MessageSource messageSource, Method method) Variant ofHandlerMethod(String, BeanFactory, Method)
that also accepts aMessageSource
.protected
HandlerMethod
(HandlerMethod handlerMethod) Copy constructor for use in subclasses. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.If the provided instance contains a bean name rather than an object instance, the bean name is resolved before aHandlerMethod
is created and returned.boolean
protected static Object
findProvidedArgument
(MethodParameter parameter, Object... providedArgs) protected static String
formatArgumentError
(MethodParameter param, String message) protected String
formatInvokeError
(String text, Object[] args) getBean()
Return the bean for this handler method.Class<?>
This method returns the type of the handler for this handler method.protected Method
If the bean method is a bridge method, this method returns the bridged (user-defined) method.Return the method for this handler method.<A extends Annotation>
AgetMethodAnnotation
(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.Return the method parameters for this handler method.Return the HandlerMethod from which this HandlerMethod instance was resolved viacreateWithResolvedBean()
.protected HttpStatusCode
Return the specified response status, if any.protected String
Return the associated response status reason, if any.Return the HandlerMethod return type.getReturnValueType
(Object returnValue) Return the actual return value type.Return a short representation of this handler method for log message purposes.int
hashCode()
<A extends Annotation>
booleanhasMethodAnnotation
(Class<A> annotationType) Return whether the parameter is declared with the given annotation type.boolean
isVoid()
Returntrue
if the method return type is void,false
otherwise.boolean
Whether the method arguments are a candidate for method validation, which is the case when there are parameterjakarta.validation.Constraint
annotations.boolean
Whether the method return value is a candidate for method validation, which is the case when there are methodjakarta.validation.Constraint
orjakarta.validation.Valid
annotations.toString()
-
Field Details
-
logger
Logger that is available to subclasses.
-
-
Constructor Details
-
HandlerMethod
Create an instance from a bean instance and a method. -
HandlerMethod
Variant ofHandlerMethod(Object, Method)
that also accepts aMessageSource
for use from subclasses.- Since:
- 5.3.10
-
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
Create an instance from a bean name, a method, and aBeanFactory
. The methodcreateWithResolvedBean()
may be used later to re-create theHandlerMethod
with an initialized bean. -
HandlerMethod
public HandlerMethod(String beanName, BeanFactory beanFactory, @Nullable MessageSource messageSource, Method method) Variant ofHandlerMethod(String, BeanFactory, Method)
that also accepts aMessageSource
. -
HandlerMethod
Copy constructor for use in subclasses.
-
-
Method Details
-
getBean
Return the bean for this handler method. -
getMethod
Return the method for this handler method. -
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
If the bean method is a bridge method, this method returns the bridged (user-defined) method. Otherwise, it returns the same method asgetMethod()
. -
getMethodParameters
Return the method parameters for this handler method. -
shouldValidateArguments
public boolean shouldValidateArguments()Whether the method arguments are a candidate for method validation, which is the case when there are parameterjakarta.validation.Constraint
annotations.The presence of
jakarta.validation.Valid
by itself does not trigger method validation since such parameters are already validated at the level of argument resolvers.Note: if the class is annotated with
Validated
, this method returns false, deferring to method validation via AOP proxy.- Since:
- 6.1
-
shouldValidateReturnValue
public boolean shouldValidateReturnValue()Whether the method return value is a candidate for method validation, which is the case when there are methodjakarta.validation.Constraint
orjakarta.validation.Valid
annotations.Note: if the class is annotated with
Validated
, this method returns false, deferring to method validation via AOP proxy.- Since:
- 6.1
-
getResponseStatus
Return the specified response status, if any.- Since:
- 4.3.8
- See Also:
-
getResponseStatusReason
Return the associated response status reason, if any.- Since:
- 4.3.8
- See Also:
-
getReturnType
Return the HandlerMethod return type. -
getReturnValueType
Return the actual return value type. -
isVoid
public boolean isVoid()Returntrue
if the method return type is void,false
otherwise. -
getMethodAnnotation
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.2.2.
- Parameters:
annotationType
- the type of annotation to introspect the method for- Returns:
- the annotation, or
null
if none found - See Also:
-
hasMethodAnnotation
Return whether the parameter is declared with the given annotation type.- Parameters:
annotationType
- the annotation type to look for- Since:
- 4.3
- See Also:
-
getResolvedFromHandlerMethod
Return the HandlerMethod from which this HandlerMethod instance was resolved viacreateWithResolvedBean()
. -
createWithResolvedBean
If the provided instance contains a bean name rather than an object instance, the bean name is resolved before aHandlerMethod
is created and returned. -
getShortLogMessage
Return a short representation of this handler method for log message purposes.- Since:
- 4.3
-
equals
-
hashCode
public int hashCode() -
toString
-
findProvidedArgument
@Nullable protected static Object findProvidedArgument(MethodParameter parameter, @Nullable Object... providedArgs) -
formatArgumentError
-
assertTargetBean
Assert that the target bean class is an instance of the class where the given method is declared. In some cases the actual controller instance at request- processing time may be a JDK dynamic proxy (lazy initialization, prototype beans, and others).@Controller
's that require proxying should prefer class-based proxy mechanisms. -
formatInvokeError
-