org.springframework.jms.annotation

## Class JmsListenerAnnotationBeanPostProcessor

- java.lang.Object
- - org.springframework.jms.annotation.JmsListenerAnnotationBeanPostProcessor

- All Implemented Interfaces:
    Aware, BeanFactoryAware, BeanPostProcessor, SmartInitializingSingleton, MergedBeanDefinitionPostProcessor, Ordered

      public class JmsListenerAnnotationBeanPostProcessor
      extends Object
      implements MergedBeanDefinitionPostProcessor, Ordered, BeanFactoryAware, SmartInitializingSingleton

  Bean post-processor that registers methods annotated with `JmsListener` to be invoked by a JMS message listener container created under the cover by a `JmsListenerContainerFactory` according to the attributes of the annotation.

  Annotated methods can use flexible arguments as defined by `JmsListener`.

  This post-processor is automatically registered by Spring's `<jms:annotation-driven>` XML element, and also by the `EnableJms` annotation.

  Autodetects any `JmsListenerConfigurer` instances in the container, allowing for customization of the registry to be used, the default container factory or for fine-grained control over endpoints registration. See the `EnableJms` javadocs for complete usage details.

  Since:
    4.1
  Author:
    Stephane Nicoll, Juergen Hoeller
  See Also:
    `JmsListener`, `EnableJms`, `JmsListenerConfigurer`, `JmsListenerEndpointRegistrar`, `JmsListenerEndpointRegistry`, `JmsListenerEndpoint`, `MethodJmsListenerEndpoint`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Log` | `logger`

    - ### Fields inherited from interface org.springframework.core.Ordered

      `HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JmsListenerAnnotationBeanPostProcessor()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterSingletonsInstantiated()` Invoked right at the end of the singleton pre-instantiation phase, with a guarantee that all regular singleton beans have been created already.
    `protected MethodJmsListenerEndpoint` | `createMethodJmsListenerEndpoint()` Instantiate an empty `MethodJmsListenerEndpoint` for further configuration with provided parameters in `processJmsListener(org.springframework.jms.annotation.JmsListener, java.lang.reflect.Method, java.lang.Object)`.
    `int` | `getOrder()` Get the order value of this object.
    `Object` | `postProcessAfterInitialization(Object bean, String beanName)` Apply this `BeanPostProcessor` to the given new bean instance after any bean initialization callbacks (like InitializingBean's `afterPropertiesSet` or a custom init-method).
    `Object` | `postProcessBeforeInitialization(Object bean, String beanName)` Apply this `BeanPostProcessor` to the given new bean instance before any bean initialization callbacks (like InitializingBean's `afterPropertiesSet` or a custom init-method).
    `void` | `postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName)` Post-process the given merged bean definition for the specified bean.
    `protected void` | `processJmsListener(JmsListener jmsListener, Method mostSpecificMethod, Object bean)` Process the given `JmsListener` annotation on the given method, registering a corresponding endpoint for the given bean instance.
    `void` | `setBeanFactory(BeanFactory beanFactory)` Making a `BeanFactory` available is optional; if not set, `JmsListenerConfigurer` beans won't get autodetected and an `endpoint registry` has to be explicitly configured.
    `void` | `setContainerFactoryBeanName(String containerFactoryBeanName)` Set the name of the `JmsListenerContainerFactory` to use by default.
    `void` | `setEndpointRegistry(JmsListenerEndpointRegistry endpointRegistry)` Set the `JmsListenerEndpointRegistry` that will hold the created endpoint and manage the lifecycle of the related listener container.
    `void` | `setMessageHandlerMethodFactory(MessageHandlerMethodFactory messageHandlerMethodFactory)` Set the `MessageHandlerMethodFactory` to use to configure the message listener responsible to serve an endpoint detected by this processor.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor

      `resetBeanDefinition`

- - ### Field Detail

    - #### logger

          protected final Log logger

  - ### Constructor Detail

    - #### JmsListenerAnnotationBeanPostProcessor

          public JmsListenerAnnotationBeanPostProcessor()

  - ### Method Detail

    - #### getOrder

          public int getOrder()

      Description copied from interface: `Ordered`
      Get the order value of this object.

      Higher values are interpreted as lower priority. As a consequence, the object with the lowest value has the highest priority (somewhat analogous to Servlet `load-on-startup` values).

      Same order values will result in arbitrary sort positions for the affected objects.

      Specified by:
        `getOrder` in interface `Ordered`
      Returns:
        the order value
      See Also:
        `Ordered.HIGHEST_PRECEDENCE`, `Ordered.LOWEST_PRECEDENCE`

    - #### setContainerFactoryBeanName

          public void setContainerFactoryBeanName(String containerFactoryBeanName)

      Set the name of the `JmsListenerContainerFactory` to use by default.

      If none is specified, "jmsListenerContainerFactory" is assumed to be defined.

    - #### setEndpointRegistry

          public void setEndpointRegistry(JmsListenerEndpointRegistry endpointRegistry)

      Set the `JmsListenerEndpointRegistry` that will hold the created endpoint and manage the lifecycle of the related listener container.

    - #### setMessageHandlerMethodFactory

          public void setMessageHandlerMethodFactory(MessageHandlerMethodFactory messageHandlerMethodFactory)

      Set the `MessageHandlerMethodFactory` to use to configure the message listener responsible to serve an endpoint detected by this processor.

      By default, `DefaultMessageHandlerMethodFactory` is used and it can be configured further to support additional method arguments or to customize conversion and validation support. See `DefaultMessageHandlerMethodFactory` Javadoc for more details.

    - #### setBeanFactory

          public void setBeanFactory(BeanFactory beanFactory)

      Making a `BeanFactory` available is optional; if not set, `JmsListenerConfigurer` beans won't get autodetected and an `endpoint registry` has to be explicitly configured.
      Specified by:
        `setBeanFactory` in interface `BeanFactoryAware`
      Parameters:
        `beanFactory` - owning BeanFactory (never `null`). The bean can immediately call methods on the factory.
      See Also:
        `BeanInitializationException`

    - #### afterSingletonsInstantiated

          public void afterSingletonsInstantiated()

      Description copied from interface: `SmartInitializingSingleton`
      Invoked right at the end of the singleton pre-instantiation phase, with a guarantee that all regular singleton beans have been created already. `ListableBeanFactory.getBeansOfType(java.lang.Class<T>)` calls within this method won't trigger accidental side effects during bootstrap.

      NOTE: This callback won't be triggered for singleton beans lazily initialized on demand after `BeanFactory` bootstrap, and not for any other bean scope either. Carefully use it for beans with the intended bootstrap semantics only.

      Specified by:
        `afterSingletonsInstantiated` in interface `SmartInitializingSingleton`

    - #### postProcessMergedBeanDefinition

          public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition,
                                                      Class<?> beanType,
                                                      String beanName)

      Description copied from interface: `MergedBeanDefinitionPostProcessor`
      Post-process the given merged bean definition for the specified bean.
      Specified by:
        `postProcessMergedBeanDefinition` in interface `MergedBeanDefinitionPostProcessor`
      Parameters:
        `beanDefinition` - the merged bean definition for the bean
        `beanType` - the actual type of the managed bean instance
        `beanName` - the name of the bean
      See Also:
        `AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Class<?>, java.lang.String)`

    - #### postProcessBeforeInitialization

          public Object postProcessBeforeInitialization(Object bean,
                                                        String beanName)
                                                 throws BeansException

      Description copied from interface: `BeanPostProcessor`
      Apply this `BeanPostProcessor` to the given new bean instance before any bean initialization callbacks (like InitializingBean's `afterPropertiesSet` or a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.

      The default implementation returns the given `bean` as-is.

      Specified by:
        `postProcessBeforeInitialization` in interface `BeanPostProcessor`
      Parameters:
        `bean` - the new bean instance
        `beanName` - the name of the bean
      Returns:
        the bean instance to use, either the original or a wrapped one; if `null`, no subsequent BeanPostProcessors will be invoked
      Throws:
        `BeansException` - in case of errors
      See Also:
        `InitializingBean.afterPropertiesSet()`

    - #### postProcessAfterInitialization

          public Object postProcessAfterInitialization(Object bean,
                                                       String beanName)
                                                throws BeansException

      Description copied from interface: `BeanPostProcessor`
      Apply this `BeanPostProcessor` to the given new bean instance after any bean initialization callbacks (like InitializingBean's `afterPropertiesSet` or a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.

      In case of a FactoryBean, this callback will be invoked for both the FactoryBean instance and the objects created by the FactoryBean (as of Spring 2.0). The post-processor can decide whether to apply to either the FactoryBean or created objects or both through corresponding `bean instanceof FactoryBean` checks.

      This callback will also be invoked after a short-circuiting triggered by a `InstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation(java.lang.Class<?>, java.lang.String)` method, in contrast to all other `BeanPostProcessor` callbacks.

      The default implementation returns the given `bean` as-is.

      Specified by:
        `postProcessAfterInitialization` in interface `BeanPostProcessor`
      Parameters:
        `bean` - the new bean instance
        `beanName` - the name of the bean
      Returns:
        the bean instance to use, either the original or a wrapped one; if `null`, no subsequent BeanPostProcessors will be invoked
      Throws:
        `BeansException` - in case of errors
      See Also:
        `InitializingBean.afterPropertiesSet()`, `FactoryBean`

    - #### processJmsListener

          protected void processJmsListener(JmsListener jmsListener,
                                            Method mostSpecificMethod,
                                            Object bean)

      Process the given `JmsListener` annotation on the given method, registering a corresponding endpoint for the given bean instance.
      Parameters:
        `jmsListener` - the annotation to process
        `mostSpecificMethod` - the annotated method
        `bean` - the instance to invoke the method on
      See Also:
        `createMethodJmsListenerEndpoint()`, `JmsListenerEndpointRegistrar.registerEndpoint(org.springframework.jms.config.JmsListenerEndpoint, org.springframework.jms.config.JmsListenerContainerFactory<?>)`

    - #### createMethodJmsListenerEndpoint

          protected MethodJmsListenerEndpoint createMethodJmsListenerEndpoint()

      Instantiate an empty `MethodJmsListenerEndpoint` for further configuration with provided parameters in `processJmsListener(org.springframework.jms.annotation.JmsListener, java.lang.reflect.Method, java.lang.Object)`.
      Returns:
        a new `MethodJmsListenerEndpoint` or subclass thereof
      Since:
        4.1.9
      See Also:
        `MethodJmsListenerEndpoint.createMessageListenerInstance()`