4 Replies Latest reply on Aug 14, 2011 7:59 AM by yairogen

    Simple Spring 3 example

    yairogen

      Hi,

       

      I want to use HornetQ in Standard standalone version. Having trouble using it with Spring.

       

      I have this xml snippet:

       

       

      <bean name="connectionFactory" class="org.hornetq.jms.client.HornetQConnectionFactory">
                          <constructor-arg name="ha" value="false"/>
                          <constructor-arg>
                                    <bean class="org.hornetq.api.core.TransportConfiguration">
                                              <constructor-arg
                                                        value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" />
                                              <!-- <constructor-arg>
                                                        <map key-type="java.lang.String" value-type="java.lang.Object">
                                                                  <entry key="port" value="5445"></entry>
                                                        </map>
                                              </constructor-arg> -->
                                    </bean>
                          </constructor-arg>
                </bean>
      
      
                <bean name="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
                          <property name="connectionFactory" ref="connectionFactory"></property>
                </bean>
      
      

       

      This fails of course on:

       

      Caused by: java.lang.IllegalStateException: Cannot convert value of type [org.hornetq.jms.client.HornetQConnectionFactory] to required type [javax.jms.ConnectionFactory] for property 'connectionFactory': no matching editors or conversion strategy found

       

      Can anyone point me to a simple workking example? On the net most of the examples either use JNDI or are out-of-date and are not adapted to latest Spring and HornetQ versions.

       

      Thanks,

       

      Yair

        • 1. Re: Simple Spring 3 example
          anastopoulos

          Hi, I'm running on JBoss and experiencing the same problem.

          Below is an excerpt of my spring config:

           

          <bean name="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">

              <property name="jndiName" value="connectionfactoryJndi" />

          </bean>

           

          <bean name="destination" class="org.springframework.jndi.JndiObjectFactoryBean">

              <property name="jndiName" value="destinationJndi" />

          </bean>

           

          <bean name="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">

              <property name="connectionFactory" ref="jmsConnectionFactory" />

              <property name="defaultDestination" ref="destination" />

              <property name="receiveTimeout" value="1" />

              <property name="sessionTransacted" value="true" />

          </bean>

           

          And the error:

           

          15:39:47,523 ERROR [org.springframework.web.context.ContextLoader] Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsTemplate' defined in ServletContext resource [/WEB-INF/classes/bus-context-resources.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.hornetq.jms.client.HornetQConnectionFactory' to required type 'javax.jms.ConnectionFactory' for property 'connectionFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.hornetq.jms.client.HornetQConnectionFactory] to required type [javax.jms.ConnectionFactory] for property 'connectionFactory': no matching editors or co

          nversion strategy found

                  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) [:3.0.5.RELEASE]

                  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [:3.0.5.RELEASE]

                  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) [:3.0.5.RELEASE]

                  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [:3.0.5.RELEASE]

                  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) [:3.0.5.RELEASE]

                  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) [:3.0.5.RELEASE]

                  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580) [:3.0.5.RELEASE]

                  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) [:3.0.5.RELEASE]

                  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) [:3.0.5.RELEASE]

                  at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276) [:3.0.5.RELEASE]

          ...

          Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.hornetq.jms.client.HornetQConnectionFactory' to required type 'javax.jms.ConnectionFactory' for property 'connectionFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.hornetq.jms.client.HornetQConnectionFactory] to required type [javax.jms.ConnectionFactory] for property 'connectionFactory': no matching editors or conversion strategy found

                  at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:462) [:3.0.5.RELEASE]

                  at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:499) [:3.0.5.RELEASE]

                  at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:493) [:3.0.5.RELEASE]

                  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1371) [:3.0.5.RELEASE]

                  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1330) [:3.0.5.RELEASE]

                  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086) [:3.0.5.RELEASE]

                  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) [:3.0.5.RELEASE]

                  ... 86 more

          Caused by: java.lang.IllegalStateException: Cannot convert value of type [org.hornetq.jms.client.HornetQConnectionFactory] to required type [javax.jms.ConnectionFactory] for property 'connectionFactory': no matching editors or conversion strategy found

                  at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231) [:3.0.5.RELEASE]

                  at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:447) [:3.0.5.RELEASE]

                  ... 92 more

           

          What's happening? How to fix it?

           

          Thanks.

          • 2. Re: Simple Spring 3 example
            beve

            Hi,

             

            could you try using 'org.hornetq.jms.client.HornetQJMSConnectionFactory' and see if that works?

             

            Regards,

             

            /Daniel

            • 3. Re: Simple Spring 3 example
              anastopoulos

              Thanks Daniel for your reply.

              I'm just getting an object from JNDI, thus I think I cannot "chose" its type.

               

              I suspected a problem of class version and conflict between "my" jms.jar and the one provided by JBoss. The one in my maven repository is 1.1.

              I tried to manually remove the jms.jar from the web-inf/lib of my war and this fixed the problem. Yair, can you check this point in your deployment?

              My Maven dependency scope on jms.jar became provided.

               

              Regards,

              Giorgio

              • 4. Re: Simple Spring 3 example
                yairogen

                Using "HornetQJMSConnectionFactory" did the trick for me.