I want to assign an id to jms:listener-container bean but unfortunately it does not have an id property. For instance, this does not work
<jms:listener-container id="jmsListenerContainer" concurrency="${jms.consumer.concurrency}" >
<jms:listener id="queueHandler" destination="${jms.queue.name}" ref="queueListener" />
</jms:listener-container>
To counter that, I am trying to define the container without the namespace using vanilla bean definition, like so:
<bean id="jmsListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"
p:concurrency="${jms.consumer.concurrency}" p:connection-factory="jmsConnectionFactory"
p:messageListener-ref="jmsMessageListener">
</bean>
For this to work one needs the actual implementation class of MessageListener used by the container as defining this separately does not work
<jms:listener id="jmsMessageListener" destination="${jms.queue.name}" ref="queueListener" />
This throws an The matching wildcard is strict, but no declaration can be found for element 'jms:listener'.
From documentation of AbstractMessageListenerContainer: By default, only a standard JMS MessageListener object or a Spring SessionAwareMessageListener object will be accepted.
This is quite inconclusive, so does anyone know how this can be done?
I would like to propose an answer to my own question. The default listener class created with jms:listener
is org.springframework.jms.listener.adapter.MessageListenerAdapter
Here's the complete vanilla replacement of jms namespace based configuration:
<bean class="org.springframework.jms.listener.adapter.MessageListenerAdapter" id="jmsMessageListener"
p:delegate-ref="queueListener" />
<!-- Not using jms namespace, as it doesn't allow to specify bean id -->
<bean id="jmsListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"
p:concurrency="${jms.consumer.concurrency}" p:connection-factory-ref="jmsConnectionFactory"
p:messageListener-ref="jmsMessageListener" p:destinationName="${jms.queue.name}" >
</bean>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments