Class HandlerMethod

java.lang.Object
org.springframework.core.annotation.AnnotatedMethod
org.springframework.messaging.handler.HandlerMethod
Direct Known Subclasses:
InvocableHandlerMethod, InvocableHandlerMethod

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 (for example, lazy-init bean, prototype bean). Use createWithResolvedBean() to obtain a HandlerMethod instance with a bean instance resolved through the associated BeanFactory.

Since:
4.0
Author:
Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller
  • Field Details

    • defaultLogger

      public static final org.apache.commons.logging.Log defaultLogger
      Public for wrapping with fallback logger.
    • logger

      protected org.apache.commons.logging.Log logger
  • Constructor Details

    • HandlerMethod

      public HandlerMethod(Object bean, Method method)
      Create an instance from a bean instance and a method.
    • 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, BeanFactory beanFactory, Method method)
      Create an instance from a bean name, a method, and a BeanFactory. The method createWithResolvedBean() may be used later to re-create the HandlerMethod with an initialized bean.
    • HandlerMethod

      protected HandlerMethod(HandlerMethod handlerMethod)
      Copy constructor for use in subclasses.
  • Method Details

    • setLogger

      public void setLogger(org.apache.commons.logging.Log logger)
      Set an alternative logger to use than the one based on the class name.
      Parameters:
      logger - the logger to use
      Since:
      5.1
    • getLogger

      public org.apache.commons.logging.Log getLogger()
      Return the currently configured Logger.
      Since:
      5.1
    • 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.
      Overrides:
      getContainingClass in class AnnotatedMethod
      See Also:
    • getResolvedFromHandlerMethod

      public @Nullable HandlerMethod getResolvedFromHandlerMethod()
      Return the HandlerMethod from which this HandlerMethod instance was resolved via createWithResolvedBean().
      Since:
      4.3
    • 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)
      Overrides:
      equals in class AnnotatedMethod
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class AnnotatedMethod
    • assertTargetBean

      protected void assertTargetBean(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. In some cases the actual endpoint instance at request- processing time may be a JDK dynamic proxy (lazy initialization, prototype beans, and others). Endpoint classes that require proxying should prefer class-based proxy mechanisms.
    • formatInvokeError

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