类 ApplicationListenerMethodAdapter

java.lang.Object
cn.taketoday.context.event.ApplicationListenerMethodAdapter
所有已实现的接口:
ApplicationListener<ApplicationEvent>, GenericApplicationListener, SmartApplicationListener, cn.taketoday.core.Ordered, EventListener

public class ApplicationListenerMethodAdapter extends Object implements GenericApplicationListener, cn.taketoday.core.Ordered
GenericApplicationListener adapter that delegates the processing of an event to an EventListener annotated method.

Delegates to onApplicationEvent(ApplicationEvent) to give subclasses a chance to deviate from the default. Unwraps the content of a PayloadApplicationEvent if necessary to allow a method declaration to define any arbitrary event type. If a condition is defined, it is evaluated prior to invoking the underlying method.

从以下版本开始:
4.0
作者:
Stephane Nicoll, Juergen Hoeller, Sam Brannen, TODAY 2021/11/5 11:51
  • 构造器详细资料

    • ApplicationListenerMethodAdapter

      public ApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method)
      Construct a new MethodApplicationListener.
      参数:
      beanName - the name of the bean to invoke the listener method on
      targetClass - the target class that the method is declared on
      method - the listener method to invoke
  • 方法详细资料

    • init

      protected void init(ApplicationContext context, @Nullable cn.taketoday.context.event.EventExpressionEvaluator evaluator)
    • getOrder

      public int getOrder()
      从接口复制的说明: SmartApplicationListener
      Determine this listener's order in a set of listeners for the same event.

      The default implementation returns Ordered.LOWEST_PRECEDENCE.

      指定者:
      getOrder 在接口中 cn.taketoday.core.Ordered
      指定者:
      getOrder 在接口中 SmartApplicationListener
    • getTargetBean

      protected Object getTargetBean()
      Return the target bean instance to use.
    • getTargetMethod

      protected Method getTargetMethod()
      Return the target listener method.
    • getCondition

      @Nullable protected String getCondition()
      Return the condition to use.

      Matches the condition attribute of the EventListener annotation or any matching attribute on a composed annotation that is meta-annotated with @EventListener.

    • supportsEventType

      public boolean supportsEventType(cn.taketoday.core.ResolvableType eventType)
      从接口复制的说明: GenericApplicationListener
      Determine whether this listener actually supports the given event type.
      指定者:
      supportsEventType 在接口中 GenericApplicationListener
      参数:
      eventType - the event type (never null)
    • supportsSourceType

      public boolean supportsSourceType(@Nullable Class<?> sourceType)
      从接口复制的说明: SmartApplicationListener
      Determine whether this listener actually supports the given source type.

      The default implementation always returns true.

      指定者:
      supportsSourceType 在接口中 SmartApplicationListener
      参数:
      sourceType - the source type, or null if no source
    • onApplicationEvent

      public void onApplicationEvent(ApplicationEvent event)
      Process the specified Object, checking if the condition matches and handling a non-null result, if any.
      指定者:
      onApplicationEvent 在接口中 ApplicationListener<ApplicationEvent>
      参数:
      event - the event to respond to
    • resolveArguments

      @Nullable protected Object[] resolveArguments(ApplicationEvent event)
      Resolve the method arguments to use for the specified ApplicationEvent.

      These arguments will be used to invoke the method handled by this instance. Can return null to indicate that no suitable arguments could be resolved and therefore the method should not be invoked at all for the specified event.

    • doInvoke

      @Nullable protected Object doInvoke(Object[] args)
      Invoke the event listener method with the given argument values.
    • getListenerId

      @Nullable public String getListenerId()
      从接口复制的说明: SmartApplicationListener
      Return an optional identifier for the listener.

      The default value is an empty String.

      指定者:
      getListenerId 在接口中 SmartApplicationListener
      另请参阅:
    • getDefaultListenerId

      protected String getDefaultListenerId()
      Determine the default id for the target listener, to be applied in case of no annotation-specified id value.

      The default implementation builds a method name with parameter types.

      另请参阅:
    • handleResult

      protected void handleResult(Object result)
    • handleAsyncError

      protected void handleAsyncError(Throwable t)
    • getDetailedErrorMessage

      protected String getDetailedErrorMessage(Object bean, String message)
      Add additional details such as the bean type and method signature to the given error message.
      参数:
      message - error message to append the HandlerMethod details to