public class JmsListenerAnnotationBeanPostProcessor extends java.lang.Object implements BeanPostProcessor, Ordered, ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>
JmsListener
to be invoked by a JMS message listener container created under the cover
by a JmsListenerContainerFactory
according
to the parameters 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.
Auto-detect 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
EnableJms
Javadoc for complete usage details.
JmsListener
,
EnableJms
,
JmsListenerConfigurer
,
JmsListenerEndpointRegistrar
,
JmsListenerEndpointRegistry
,
AbstractJmsListenerEndpoint
,
MethodJmsListenerEndpoint
Modifier and Type | Class and Description |
---|---|
private class |
JmsListenerAnnotationBeanPostProcessor.JmsHandlerMethodFactoryAdapter
An
JmsHandlerMethodFactory adapter that offers a configurable underlying
instance to use. |
Modifier and Type | Field and Description |
---|---|
private ApplicationContext |
applicationContext |
private java.lang.String |
containerFactoryBeanName |
private java.util.concurrent.atomic.AtomicInteger |
counter |
(package private) static java.lang.String |
DEFAULT_JMS_LISTENER_CONTAINER_FACTORY_BEAN_NAME
The bean name of the default
JmsListenerContainerFactory |
private JmsListenerEndpointRegistry |
endpointRegistry |
private JmsListenerAnnotationBeanPostProcessor.JmsHandlerMethodFactoryAdapter |
jmsHandlerMethodFactory |
private JmsListenerEndpointRegistrar |
registrar |
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
JmsListenerAnnotationBeanPostProcessor() |
Modifier and Type | Method and Description |
---|---|
private java.lang.String |
getEndpointId(JmsListener jmsListener) |
int |
getOrder()
Return the order value of this object, with a
higher value meaning greater in terms of sorting.
|
void |
onApplicationEvent(ContextRefreshedEvent event)
Handle an application event.
|
java.lang.Object |
postProcessAfterInitialization(java.lang.Object bean,
java.lang.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). |
java.lang.Object |
postProcessBeforeInitialization(java.lang.Object bean,
java.lang.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). |
protected void |
processJmsListener(JmsListener jmsListener,
java.lang.reflect.Method method,
java.lang.Object bean) |
void |
setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext that this object runs in.
|
void |
setContainerFactoryBeanName(java.lang.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 |
setJmsHandlerMethodFactory(JmsHandlerMethodFactory jmsHandlerMethodFactory)
Set the
JmsHandlerMethodFactory to use to configure the message
listener responsible to serve an endpoint detected by this processor. |
static final java.lang.String DEFAULT_JMS_LISTENER_CONTAINER_FACTORY_BEAN_NAME
JmsListenerContainerFactory
private JmsListenerEndpointRegistry endpointRegistry
private java.lang.String containerFactoryBeanName
private final JmsListenerAnnotationBeanPostProcessor.JmsHandlerMethodFactoryAdapter jmsHandlerMethodFactory
private ApplicationContext applicationContext
private final JmsListenerEndpointRegistrar registrar
private final java.util.concurrent.atomic.AtomicInteger counter
public JmsListenerAnnotationBeanPostProcessor()
public int getOrder()
Ordered
Normally starting with 0, with Integer.MAX_VALUE
indicating the greatest value. Same order values will result
in arbitrary positions for the affected objects.
Higher values can be interpreted as lower priority. As a consequence, the object with the lowest value has highest priority (somewhat analogous to Servlet "load-on-startup" values).
public void setEndpointRegistry(JmsListenerEndpointRegistry endpointRegistry)
JmsListenerEndpointRegistry
that will hold the created
endpoint and manage the lifecycle of the related listener container.public void setContainerFactoryBeanName(java.lang.String containerFactoryBeanName)
JmsListenerContainerFactory
to use by default.
If none is specified, "jmsListenerContainerFactory" is assumed to be defined.
public void setJmsHandlerMethodFactory(JmsHandlerMethodFactory jmsHandlerMethodFactory)
JmsHandlerMethodFactory
to use to configure the message
listener responsible to serve an endpoint detected by this processor.
By default, DefaultJmsHandlerMethodFactory
is used and it
can be configured further to support additional method arguments
or to customize conversion and validation support. See
DefaultJmsHandlerMethodFactory
Javadoc for more details.
public void setApplicationContext(ApplicationContext applicationContext)
ApplicationContextAware
Invoked after population of normal bean properties but before an init callback such
as InitializingBean.afterPropertiesSet()
or a custom init-method. Invoked after ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)
,
ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
and
MessageSourceAware
, if applicable.
setApplicationContext
in interface ApplicationContextAware
applicationContext
- the ApplicationContext object to be used by this objectBeanInitializationException
public java.lang.Object postProcessBeforeInitialization(java.lang.Object bean, java.lang.String beanName) throws BeansException
BeanPostProcessor
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.postProcessBeforeInitialization
in interface BeanPostProcessor
bean
- the new bean instancebeanName
- the name of the beannull
, no subsequent BeanPostProcessors will be invokedBeansException
- in case of errorsInitializingBean.afterPropertiesSet()
public java.lang.Object postProcessAfterInitialization(java.lang.Object bean, java.lang.String beanName) throws BeansException
BeanPostProcessor
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.
postProcessAfterInitialization
in interface BeanPostProcessor
bean
- the new bean instancebeanName
- the name of the beannull
, no subsequent BeanPostProcessors will be invokedBeansException
- in case of errorsInitializingBean.afterPropertiesSet()
,
FactoryBean
protected void processJmsListener(JmsListener jmsListener, java.lang.reflect.Method method, java.lang.Object bean)
public void onApplicationEvent(ContextRefreshedEvent event)
ApplicationListener
onApplicationEvent
in interface ApplicationListener<ContextRefreshedEvent>
event
- the event to respond toprivate java.lang.String getEndpointId(JmsListener jmsListener)