Package org.springframework.web.method
Class HandlerMethod
java.lang.Object
org.springframework.core.annotation.AnnotatedMethod
org.springframework.web.method.HandlerMethod
- Direct Known Subclasses:
InvocableHandlerMethod
public class HandlerMethod
extends org.springframework.core.annotation.AnnotatedMethod
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:
- 3.1
- Author:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Sam Brannen
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.core.annotation.AnnotatedMethod
org.springframework.core.annotation.AnnotatedMethod.AnnotatedMethodParameter -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.apache.commons.logging.LogLogger that is available to subclasses. -
Constructor Summary
ConstructorsModifierConstructorDescriptionHandlerMethod(Object bean, Method method) Create an instance from a bean instance and a method.protectedHandlerMethod(Object bean, Method method, org.springframework.context.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, org.springframework.beans.factory.BeanFactory beanFactory, Method method) Create an instance from a bean name, a method, and aBeanFactory.HandlerMethod(String beanName, org.springframework.beans.factory.BeanFactory beanFactory, org.springframework.context.MessageSource messageSource, Method method) Variant ofHandlerMethod(String, BeanFactory, Method)that also accepts aMessageSource.protectedHandlerMethod(HandlerMethod handlerMethod) Copy constructor for use in subclasses. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidassertTargetBean(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 aHandlerMethodis created and returned.booleanprotected StringformatInvokeError(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 Class<?>Return the HandlerMethod from which this HandlerMethod instance was resolved viacreateWithResolvedBean().protected HttpStatusCodeReturn the specified response status, if any.protected StringReturn 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.AnnotatedMethod
findProvidedArgument, formatArgumentError, getBridgedMethod, getMethod, getMethodAnnotation, getMethodParameters, getReturnType, getReturnValueType, hasMethodAnnotation, isVoid
-
Field Details
-
logger
protected static final org.apache.commons.logging.Log loggerLogger that is available to subclasses.
-
-
Constructor Details
-
HandlerMethod
Create an instance from a bean instance and a method. -
HandlerMethod
protected HandlerMethod(Object bean, Method method, @Nullable org.springframework.context.MessageSource messageSource) Variant ofHandlerMethod(Object, Method)that also accepts aMessageSourcefor 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
public HandlerMethod(String beanName, org.springframework.beans.factory.BeanFactory beanFactory, Method method) Create an instance from a bean name, a method, and aBeanFactory. The methodcreateWithResolvedBean()may be used later to re-create theHandlerMethodwith an initialized bean. -
HandlerMethod
public HandlerMethod(String beanName, org.springframework.beans.factory.BeanFactory beanFactory, @Nullable org.springframework.context.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. -
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.
-
getContainingClass
- Overrides:
getContainingClassin classorg.springframework.core.annotation.AnnotatedMethod
-
shouldValidateArguments
public 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
-
shouldValidateReturnValue
public 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
-
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:
-
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 aHandlerMethodis created and returned. -
getShortLogMessage
Return a short representation of this handler method for log message purposes.- Since:
- 4.3
-
equals
- Overrides:
equalsin classorg.springframework.core.annotation.AnnotatedMethod
-
hashCode
public int hashCode()- Overrides:
hashCodein classorg.springframework.core.annotation.AnnotatedMethod
-
toString
- Overrides:
toStringin classorg.springframework.core.annotation.AnnotatedMethod
-
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
-