public class JmsListenerAnnotationBeanPostProcessor extends java.lang.Object implements MergedBeanDefinitionPostProcessor, Ordered, BeanFactoryAware, SmartInitializingSingleton
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.
JmsListener
,
EnableJms
,
JmsListenerConfigurer
,
JmsListenerEndpointRegistrar
,
JmsListenerEndpointRegistry
,
JmsListenerEndpoint
,
MethodJmsListenerEndpoint
Modifier and Type | Class and Description |
---|---|
private class |
JmsListenerAnnotationBeanPostProcessor.MessageHandlerMethodFactoryAdapter
A
MessageHandlerMethodFactory adapter that offers a configurable underlying
instance to use. |
Modifier and Type | Field and Description |
---|---|
private BeanFactory |
beanFactory |
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 StringValueResolver |
embeddedValueResolver |
private JmsListenerEndpointRegistry |
endpointRegistry |
protected Log |
logger |
private JmsListenerAnnotationBeanPostProcessor.MessageHandlerMethodFactoryAdapter |
messageHandlerMethodFactory |
private java.util.Set<java.lang.Class<?>> |
nonAnnotatedClasses |
private JmsListenerEndpointRegistrar |
registrar |
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
JmsListenerAnnotationBeanPostProcessor() |
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) . |
private java.lang.String |
getEndpointId(JmsListener jmsListener) |
int |
getOrder()
Get the order value of this object.
|
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). |
void |
postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition,
java.lang.Class<?> beanType,
java.lang.String beanName)
Post-process the given merged bean definition for the specified bean.
|
protected void |
processJmsListener(JmsListener jmsListener,
java.lang.reflect.Method mostSpecificMethod,
java.lang.Object bean)
Process the given
JmsListener annotation on the given method,
registering a corresponding endpoint for the given bean instance. |
private java.lang.String |
resolve(java.lang.String value) |
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(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 |
setMessageHandlerMethodFactory(MessageHandlerMethodFactory messageHandlerMethodFactory)
Set the
MessageHandlerMethodFactory 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
.protected final Log logger
private JmsListenerEndpointRegistry endpointRegistry
private java.lang.String containerFactoryBeanName
private final JmsListenerAnnotationBeanPostProcessor.MessageHandlerMethodFactoryAdapter messageHandlerMethodFactory
private BeanFactory beanFactory
private StringValueResolver embeddedValueResolver
private final JmsListenerEndpointRegistrar registrar
private final java.util.concurrent.atomic.AtomicInteger counter
private final java.util.Set<java.lang.Class<?>> nonAnnotatedClasses
public JmsListenerAnnotationBeanPostProcessor()
public int getOrder()
Ordered
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.
getOrder
in interface Ordered
Ordered.HIGHEST_PRECEDENCE
,
Ordered.LOWEST_PRECEDENCE
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 setMessageHandlerMethodFactory(MessageHandlerMethodFactory messageHandlerMethodFactory)
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.
public void setBeanFactory(BeanFactory beanFactory)
BeanFactory
available is optional; if not set,
JmsListenerConfigurer
beans won't get autodetected and an
endpoint registry
has to be explicitly configured.setBeanFactory
in interface BeanFactoryAware
beanFactory
- owning BeanFactory (never null
).
The bean can immediately call methods on the factory.BeanInitializationException
public void afterSingletonsInstantiated()
SmartInitializingSingleton
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.
afterSingletonsInstantiated
in interface SmartInitializingSingleton
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, java.lang.Class<?> beanType, java.lang.String beanName)
MergedBeanDefinitionPostProcessor
postProcessMergedBeanDefinition
in interface MergedBeanDefinitionPostProcessor
beanDefinition
- the merged bean definition for the beanbeanType
- the actual type of the managed bean instancebeanName
- the name of the beanpublic 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.
The default implementation returns the given bean
as-is.
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.
The default implementation returns the given bean
as-is.
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 mostSpecificMethod, java.lang.Object bean)
JmsListener
annotation on the given method,
registering a corresponding endpoint for the given bean instance.jmsListener
- the annotation to processmostSpecificMethod
- the annotated methodbean
- the instance to invoke the method oncreateMethodJmsListenerEndpoint()
,
JmsListenerEndpointRegistrar.registerEndpoint(org.springframework.jms.config.JmsListenerEndpoint, org.springframework.jms.config.JmsListenerContainerFactory<?>)
protected MethodJmsListenerEndpoint createMethodJmsListenerEndpoint()
MethodJmsListenerEndpoint
for further
configuration with provided parameters in processJmsListener(org.springframework.jms.annotation.JmsListener, java.lang.reflect.Method, java.lang.Object)
.MethodJmsListenerEndpoint
or subclass thereofMethodJmsListenerEndpoint.createMessageListenerInstance()
private java.lang.String getEndpointId(JmsListener jmsListener)
private java.lang.String resolve(java.lang.String value)