Class HandlerMethod
- Direct Known Subclasses:
- InvocableHandlerMethod,- InvocableHandlerMethod,- SyncInvocableHandlerMethod
The class may be created with a bean instance or with a bean name
 (for example, 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 SummaryNested classes/interfaces inherited from class org.springframework.core.annotation.AnnotatedMethodAnnotatedMethod.AnnotatedMethodParameter
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected static final org.apache.commons.logging.LogLogger that is available to subclasses.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionHandlerMethod(Object bean, Method method) Create an instance from a bean instance and a method.protectedHandlerMethod(Object bean, Method method, @Nullable MessageSource messageSource) Variant ofHandlerMethod(Object, Method)that also accepts aMessageSourcefor 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, @Nullable MessageSource messageSource, Method method) Variant ofHandlerMethod(String, BeanFactory, Method)that also accepts aMessageSource.protectedHandlerMethod(HandlerMethod handlerMethod) Copy constructor for use in subclasses.protectedHandlerMethod(HandlerMethod handlerMethod, @Nullable Object handler, boolean initValidateFlags) Re-create new HandlerMethod instance that copies the given HandlerMethod but replaces the handler, and optionally checks for the presence of validation annotations.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidassertTargetBean(Method method, Object targetBean, @Nullable Object[] args) Assert that the target bean class is an instance of the class where the given method is declared.If thehandleris a bean name rather than the actual handler instance, resolve the bean name through Spring configuration (e.g.Re-create the HandlerMethod and initializeshouldValidateArguments()andshouldValidateReturnValue().booleanprotected StringformatInvokeError(String text, @Nullable Object[] args) getBean()Return the bean for this handler method.Class<?> This method returns the type of the handler for this handler method.protected Class<?> Expose the containing class for method parameters.Return the HandlerMethod from which this HandlerMethod instance was resolved viacreateWithResolvedBean().protected @Nullable HttpStatusCodeReturn the specified response status, if any.Return the associated response status reason, if any.Return a short representation of this handler method for log message purposes.inthashCode()booleanWhether the method arguments are a candidate for method validation, which is the case when there are parameterjakarta.validation.Constraintannotations.booleanWhether the method return value is a candidate for method validation, which is the case when there are methodjakarta.validation.Constraintorjakarta.validation.Validannotations.toString()Methods inherited from class org.springframework.core.annotation.AnnotatedMethodfindProvidedArgument, formatArgumentError, getBridgedMethod, getMethod, getMethodAnnotation, getMethodParameters, getReturnType, getReturnValueType, hasMethodAnnotation, isVoid
- 
Field Details- 
loggerprotected static final org.apache.commons.logging.Log loggerLogger that is available to subclasses.
 
- 
- 
Constructor Details- 
HandlerMethod
- 
HandlerMethodVariant ofHandlerMethod(Object, Method)that also accepts aMessageSourcefor use from subclasses.- Since:
- 5.3.10
 
- 
HandlerMethodpublic 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
 
- 
HandlerMethodCreate an instance from a bean name, a method, and aBeanFactory. The methodcreateWithResolvedBean()may be used later to re-create theHandlerMethodwith an initialized bean.
- 
HandlerMethodpublic HandlerMethod(String beanName, BeanFactory beanFactory, @Nullable MessageSource messageSource, Method method) Variant ofHandlerMethod(String, BeanFactory, Method)that also accepts aMessageSource.
- 
HandlerMethodCopy constructor for use in subclasses.
- 
HandlerMethodprotected HandlerMethod(HandlerMethod handlerMethod, @Nullable Object handler, boolean initValidateFlags) Re-create new HandlerMethod instance that copies the given HandlerMethod but replaces the handler, and optionally checks for the presence of validation annotations.Subclasses can override this to ensure that a HandlerMethod is of the same type if re-created. - Since:
- 6.2.3
 
 
- 
- 
Method Details- 
getBeanReturn the bean for this handler method.
- 
getBeanTypeThis 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. 
- 
getContainingClassDescription copied from class:AnnotatedMethodExpose the containing class for method parameters.- Overrides:
- getContainingClassin class- AnnotatedMethod
- See Also:
 
- 
shouldValidateArgumentspublic boolean shouldValidateArguments()Whether the method arguments are a candidate for method validation, which is the case when there are parameterjakarta.validation.Constraintannotations.The presence of jakarta.validation.Validby 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
 
- 
shouldValidateReturnValuepublic boolean shouldValidateReturnValue()Whether the method return value is a candidate for method validation, which is the case when there are methodjakarta.validation.Constraintorjakarta.validation.Validannotations.Note: if the class is annotated with Validated, this method returns false, deferring to method validation via AOP proxy.- Since:
- 6.1
 
- 
getResponseStatusReturn the specified response status, if any.- Since:
- 4.3.8
- See Also:
 
- 
getResponseStatusReason
- 
getResolvedFromHandlerMethodReturn the HandlerMethod from which this HandlerMethod instance was resolved viacreateWithResolvedBean().
- 
createWithValidateFlagsRe-create the HandlerMethod and initializeshouldValidateArguments()andshouldValidateReturnValue().- Since:
- 6.1.3
 
- 
createWithResolvedBeanIf thehandleris a bean name rather than the actual handler instance, resolve the bean name through Spring configuration (e.g. for prototype beans), and return a newHandlerMethodinstance with the resolved handler.If the handleris not String, return the same instance.
- 
getShortLogMessageReturn a short representation of this handler method for log message purposes.- Since:
- 4.3
 
- 
equals- Overrides:
- equalsin class- AnnotatedMethod
 
- 
hashCodepublic int hashCode()- Overrides:
- hashCodein class- AnnotatedMethod
 
- 
toString- Overrides:
- toStringin class- AnnotatedMethod
 
- 
assertTargetBeanAssert 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
 
-