Top Description Fields Constructors Methods
org.springframework.messaging.handler

public Class HandlerMethod

extends AnnotatedMethod
Class Inheritance
Known Direct Subclasses
org.springframework.messaging.handler.invocation.InvocableHandlerMethod, org.springframework.messaging.handler.invocation.reactive.InvocableHandlerMethod
Imports
java.lang.reflect.Method, java.util.stream.Collectors, .IntStream, org.apache.commons.logging.Log, .LogFactory, org.springframework.beans.factory.BeanFactory, org.springframework.core.annotation.AnnotatedMethod, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils

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.

Authors
Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller
Since
4.0

Field Summary

Modifier and TypeField and Description
private final Object
private final BeanFactory
private final Class<?>
public static final Log
defaultLogger

Public for wrapping with fallback logger.

protected Log
private HandlerMethod

Constructor Summary

AccessConstructor and Description
public
HandlerMethod(Object bean, Method method)

Create an instance from a bean instance and a method.

public
HandlerMethod(Object bean, String methodName, Class<?>... parameterTypes)

Create an instance from a bean instance, method name, and parameter types.

public
HandlerMethod(String beanName, BeanFactory beanFactory, Method method)

Create an instance from a bean name, a method, and a BeanFactory.

protected
HandlerMethod(HandlerMethod handlerMethod)

Copy constructor for use in subclasses.

private
HandlerMethod(HandlerMethod handlerMethod, Object handler)

Re-create HandlerMethod with the resolved handler.

Method Summary

Modifier and TypeMethod and Description
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.

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.

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides org.springframework.core.annotation.AnnotatedMethod.equals.

Indicates whether some other object is "equal to" this one.

protected String
public Object
getBean()

Return the bean for this handler method.

public Class<?>
getBeanType()

This method returns the type of the handler for this handler method.

protected Class<?>
getContainingClass()

Overrides org.springframework.core.annotation.AnnotatedMethod.getContainingClass.

Expose the containing class for method parameters.

public Log
getLogger()

Return the currently configured Logger.

public HandlerMethod
getResolvedFromHandlerMethod()

Return the HandlerMethod from which this HandlerMethod instance was resolved via createWithResolvedBean().

public String
getShortLogMessage()

Return a short representation of this handler method for log message purposes.

public int
hashCode()

Overrides org.springframework.core.annotation.AnnotatedMethod.hashCode.

Returns a hash code value for this object.

public void
setLogger(Log
the logger to use
logger
)

Set an alternative logger to use than the one based on the class name.

Inherited from org.springframework.core.annotation.AnnotatedMethod:
findProvidedArgumentformatArgumentErrorgetBridgedMethodgetMethodgetMethodAnnotationgetMethodParametersgetReturnTypegetReturnValueTypehasMethodAnnotationisVoidtoString

Field Detail

beanback to summary
private final Object bean
beanFactoryback to summary
private final BeanFactory beanFactory
Annotations
@Nullable
beanTypeback to summary
private final Class<?> beanType
defaultLoggerback to summary
public static final Log defaultLogger

Public for wrapping with fallback logger.

loggerback to summary
protected Log logger
resolvedFromHandlerMethodback to summary
private HandlerMethod resolvedFromHandlerMethod
Annotations
@Nullable

Constructor Detail

HandlerMethodback to summary
public HandlerMethod(Object bean, Method method)

Create an instance from a bean instance and a method.

HandlerMethodback to summary
public HandlerMethod(Object bean, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException

Create an instance from a bean instance, method name, and parameter types.

Exceptions
NoSuchMethodException:
when the method cannot be found
HandlerMethodback to summary
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.

HandlerMethodback to summary
protected HandlerMethod(HandlerMethod handlerMethod)

Copy constructor for use in subclasses.

HandlerMethodback to summary
private HandlerMethod(HandlerMethod handlerMethod, Object handler)

Re-create HandlerMethod with the resolved handler.

Method Detail

assertTargetBeanback to summary
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 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.

createWithResolvedBeanback to summary
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.

equalsback to summary
public boolean equals(Object other)

Overrides org.springframework.core.annotation.AnnotatedMethod.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
formatInvokeErrorback to summary
protected String formatInvokeError(String text, Object[] args)
getBeanback to summary
public Object getBean()

Return the bean for this handler method.

getBeanTypeback to summary
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.

getContainingClassback to summary
protected Class<?> getContainingClass()

Overrides org.springframework.core.annotation.AnnotatedMethod.getContainingClass.

Doc from org.springframework.core.annotation.AnnotatedMethod.getContainingClass.

Expose the containing class for method parameters.

Annotations
@Override
getLoggerback to summary
public Log getLogger()

Return the currently configured Logger.

Since
5.1
getResolvedFromHandlerMethodback to summary
public HandlerMethod getResolvedFromHandlerMethod()

Return the HandlerMethod from which this HandlerMethod instance was resolved via createWithResolvedBean().

Annotations
@Nullable
Since
4.3
getShortLogMessageback to summary
public String getShortLogMessage()

Return a short representation of this handler method for log message purposes.

hashCodeback to summary
public int hashCode()

Overrides org.springframework.core.annotation.AnnotatedMethod.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
setLoggerback to summary
public void setLogger(Log logger)

Set an alternative logger to use than the one based on the class name.

Parameters
logger:Log

the logger to use

Since
5.1