Class HandlerMethod

Direct Known Subclasses:
InvocableHandlerMethod, InvocableHandlerMethod, SyncInvocableHandlerMethod

public class HandlerMethod extends 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.

Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Sam Brannen
  • Field Details

    • logger

      protected static final Log logger
      Logger that is available to subclasses.
  • Constructor Details

  • Method Details

    • getBean

      public Object getBean()
      Return the bean for this handler method.
    • getBeanType

      public Class<?> 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

      protected Class<?> getContainingClass()
      Description copied from class: AnnotatedMethod
      Expose the containing class for method parameters.
      getContainingClass in class AnnotatedMethod
      See Also:
    • shouldValidateArguments

      public boolean shouldValidateArguments()
      Whether the method arguments are a candidate for method validation, which is the case when there are parameter jakarta.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.

    • shouldValidateReturnValue

      public boolean shouldValidateReturnValue()
      Whether the method return value is a candidate for method validation, which is the case when there are method jakarta.validation.Constraint or jakarta.validation.Valid annotations.

      Note: if the class is annotated with Validated, this method returns false, deferring to method validation via AOP proxy.

    • getResponseStatus

      @Nullable protected HttpStatusCode getResponseStatus()
      Return the specified response status, if any.
      See Also:
    • getResponseStatusReason

      @Nullable protected String getResponseStatusReason()
      Return the associated response status reason, if any.
      See Also:
    • getResolvedFromHandlerMethod

      @Nullable public HandlerMethod getResolvedFromHandlerMethod()
      Return the HandlerMethod from which this HandlerMethod instance was resolved via createWithResolvedBean().
    • 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.
    • getShortLogMessage

      public String getShortLogMessage()
      Return a short representation of this handler method for log message purposes.
    • equals

      public boolean equals(@Nullable Object other)
      equals in class AnnotatedMethod
    • hashCode

      public int hashCode()
      hashCode in class AnnotatedMethod
    • toString

      public String toString()
      toString in class AnnotatedMethod
    • assertTargetBean

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

      protected String formatInvokeError(String text, Object[] args)