org.springframework.messaging.handler

Class HandlerMethod

  • java.lang.Object
    • org.springframework.messaging.handler.HandlerMethod
  • Direct Known Subclasses:
    InvocableHandlerMethod


    public class HandlerMethod
    extends java.lang.Object
    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:
    4.0
    Author:
    Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class and Description
      protected class  HandlerMethod.HandlerMethodParameter
      A MethodParameter with HandlerMethod-specific behavior.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static Log defaultLogger
      Public for wrapping with fallback logger.
      protected Log logger 
    • Constructor Summary

      Constructors 
      Modifier Constructor and Description
      protected HandlerMethod(HandlerMethod handlerMethod)
      Copy constructor for use in subclasses.
        HandlerMethod(java.lang.Object bean, java.lang.reflect.Method method)
      Create an instance from a bean instance and a method.
        HandlerMethod(java.lang.Object bean, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
      Create an instance from a bean instance, method name, and parameter types.
        HandlerMethod(java.lang.String beanName, BeanFactory beanFactory, java.lang.reflect.Method method)
      Create an instance from a bean name, a method, and a BeanFactory.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      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.
      boolean equals(java.lang.Object other) 
      java.lang.Object getBean()
      Return the bean for this handler method.
      java.lang.Class<?> getBeanType()
      This method returns the type of the handler for this handler method.
      protected java.lang.reflect.Method getBridgedMethod()
      If the bean method is a bridge method, this method returns the bridged (user-defined) method.
      Log getLogger()
      Return the currently configured Logger.
      java.lang.reflect.Method getMethod()
      Return the method for this handler method.
      <A extends java.lang.annotation.Annotation>
      A
      getMethodAnnotation(java.lang.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.
      MethodParameter[] getMethodParameters()
      Return the method parameters for this handler method.
      HandlerMethod getResolvedFromHandlerMethod()
      Return the HandlerMethod from which this HandlerMethod instance was resolved via createWithResolvedBean().
      MethodParameter getReturnType()
      Return the HandlerMethod return type.
      MethodParameter getReturnValueType(java.lang.Object returnValue)
      Return the actual return value type.
      java.lang.String getShortLogMessage()
      Return a short representation of this handler method for log message purposes.
      int hashCode() 
      <A extends java.lang.annotation.Annotation>
      boolean
      hasMethodAnnotation(java.lang.Class<A> annotationType)
      Return whether the parameter is declared with the given annotation type.
      boolean isVoid()
      Return true if the method return type is void, false otherwise.
      void setLogger(Log logger)
      Set an alternative logger to use than the one based on the class name.
      java.lang.String toString() 
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • defaultLogger

        public static final Log defaultLogger
        Public for wrapping with fallback logger.
      • logger

        protected Log logger
    • Constructor Detail

      • HandlerMethod

        public HandlerMethod(java.lang.Object bean,
                             java.lang.reflect.Method method)
        Create an instance from a bean instance and a method.
      • HandlerMethod

        public HandlerMethod(java.lang.Object bean,
                             java.lang.String methodName,
                             java.lang.Class<?>... parameterTypes)
                      throws java.lang.NoSuchMethodException
        Create an instance from a bean instance, method name, and parameter types.
        Throws:
        java.lang.NoSuchMethodException - when the method cannot be found
      • HandlerMethod

        public HandlerMethod(java.lang.String beanName,
                             BeanFactory beanFactory,
                             java.lang.reflect.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 Detail

      • setLogger

        public void setLogger(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 Log getLogger()
        Return the currently configured Logger.
        Since:
        5.1
      • getBean

        public java.lang.Object getBean()
        Return the bean for this handler method.
      • getMethod

        public java.lang.reflect.Method getMethod()
        Return the method for this handler method.
      • getBeanType

        public java.lang.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.

      • getBridgedMethod

        protected java.lang.reflect.Method getBridgedMethod()
        If the bean method is a bridge method, this method returns the bridged (user-defined) method. Otherwise it returns the same method as getMethod().
      • getMethodParameters

        public MethodParameter[] getMethodParameters()
        Return the method parameters for this handler method.
      • getReturnType

        public MethodParameter getReturnType()
        Return the HandlerMethod return type.
      • getReturnValueType

        public MethodParameter getReturnValueType(@Nullable
                                                  java.lang.Object returnValue)
        Return the actual return value type.
      • isVoid

        public boolean isVoid()
        Return true if the method return type is void, false otherwise.
      • getMethodAnnotation

        @Nullable
        public <A extends java.lang.annotation.Annotation> A getMethodAnnotation(java.lang.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.

        Also supports merged composed annotations with attribute overrides as of Spring Framework 4.3.

        Parameters:
        annotationType - the type of annotation to introspect the method for
        Returns:
        the annotation, or null if none found
        See Also:
        AnnotatedElementUtils.findMergedAnnotation(java.lang.reflect.AnnotatedElement, java.lang.Class<A>)
      • 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 java.lang.String getShortLogMessage()
        Return a short representation of this handler method for log message purposes.
      • equals

        public boolean equals(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object