Results 1 to 2 of 2

Thread: DefaultMessageListenerContainer instantiation

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    19

    Default DefaultMessageListenerContainer instantiation

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

    Code:
    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:
    Code:
    <bean id="jmsMessageListener" class="com.JMSMessageSubscriber">\
      	</bean>
       
    	<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"/>
    	</bean>
    the pom.xml contains the jms dependencies - not sure what the conflict is?
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jms</artifactId>
    <version>${version.spring}</version>
    </dependency>
    <dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-all</artifactId>
    <version>5.4.3</version>
    </dependency>

    Thanks

  2. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •