Announcement Announcement Module
No announcement yet.
DefaultMessageListenerContainer instantiation Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • DefaultMessageListenerContainer instantiation

    I am getting the following error when instantiating the Jms MessageListener from the applicationContext.xml:

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsContainer' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
    PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'messageListener' threw exception; nested exception is java.lang.IllegalArgumentException: Message listener needs to be of type [javax.jms.MessageListener] or [org.springframework.jms.listener.SessionAwareMessageListener]

    Here is the code to instantiate the beans:
    <bean id="jmsMessageListener" class="com.JMSMessageSubscriber">\
    	<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    		<property name="connectionFactory" ref="cachedConnectionFactory" />
    		<property name="destination" ref="myTopic" />
    		<property name="messageListener" ref="jmsMessageListener" />
    		<property name="sessionTransacted" value="true" />
    		<property name="subscriptionDurable" value="true"/>
    the pom.xml contains the jms dependencies - not sure what the conflict is?


  • #2
    The error message is stating that the messageListener reference requires an implementation of the JMS MessageListener interface or Spring's own SessionAwareMessageListener interface. Your com.JMSMessageSubscriber class apparently does not implement either of those.

    Can you show the code for com.JMSMessageSubscriber?

    If you want to inject a POJO instead of implementing one of those interfaces, you must wrap that in Spring's MessageListenerAdapter (classic Gang-of-Four "Adapter" pattern: it implements the interface for you but delegates to your code so that it does not need to implement the interface).

    Of course, it's much easier to use the "jms" namespace in your Spring configuration. Is there a reason you are not?