1 Reply Latest reply on Oct 25, 2012 7:19 AM by Gazal KA

    Embedded hornetq using spring (Chapter 43)

    Gazal KA Newbie

      We have been trying to use an in-vm hornetq instance in our web applications. Migrating from 2.0.0.GA to 2.2.19.Final, the first blocking issue was https://community.jboss.org/message/767054.

      Now I'm trying to follow Chapter 43 of the hornetq manual.

       

      My spring configuration file for the embedded hornetq is as follows:

       

      {code:xml}  <bean name="remoteConnector" class="java.util.ArrayList">

                          <constructor-arg>

                                    <list>

                                              <value>remote-connector</value>

                                    </list>

                          </constructor-arg>

                </bean>

       

       

                <bean id="nettyConnector" 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="host" value="${JMS_HOST}"></entry>

                                              <entry key="port" value="${JMS_CONNECTOR_PORT}"></entry>

                                    </map>

                          </constructor-arg>

                          <constructor-arg value="remote-connector" />

                </bean>

       

       

                <bean name="fileConfiguration" class="org.hornetq.core.config.impl.FileConfiguration"

                          init-method="start" destroy-method="stop">

                          <property name="connectorConfigurations">

                                    <map key-type="java.lang.String" value-type="org.hornetq.api.core.TransportConfiguration">

                                              <entry key="remote-connector" value-ref="nettyConnector" />

                                    </map>

                          </property>

                          <property name="bridgeConfigurations" ref="bridgeConfigurations" />

                </bean>

       

       

                <bean id="bridgeConfigurations" class="java.util.ArrayList" />

       

       

                <bean id="embeddedJms" class="org.hornetq.integration.spring.SpringJmsBootstrap"

                          init-method="start">

                          <property name="configuration" ref="fileConfiguration" />

                </bean>{code}

       

       

      And in an application context I'm trying to use a 'ConnectionFactory' instance and the destination instance as follows:

       

      {code:xml}        <bean id="inVmJmsWriter" class="com.mycompany.utils.jms.JmsWriter">

                          <constructor-arg ref="ConnectionFactory" />

                          <constructor-arg value="false" />

                          <constructor-arg value="#{T(javax.jms.Session).AUTO_ACKNOWLEDGE}" />

                          <constructor-arg ref="/queue/NotificationsQueue" />

                          <constructor-arg value="OBJECT" />

                          <qualifier value="inVmJmsWriter" />

                </bean>{code}

       

      On context startup I'm getting the following exception:

       

      ----

      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'inVmJmsWriter' defined in class path resource [appContext.xml]: Cannot resolve reference to bean 'ConnectionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefini

      tionException: No bean named 'ConnectionFactory' is defined

              at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)

              at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)

              at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:630)

              at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:148)

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035)

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939)

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

              at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)

              at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)

              at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)

              at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)

              at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:876)

              at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818)

              at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735)

              at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)

              ... 52 more

      Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ConnectionFactory' is defined

              at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:553)

              at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)

              at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)

              at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)

              at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)

              ... 67 more

      ----

       

       

      The manual seems to use beans named 'ConnectionFactory' and destinations with their names as defined in hornetq-jms.xml.

      And it does say 'The Spring helper class starts the HornetQ server and adds any factories or destinations configured within hornetq-jms.xml directly into the namespace of the Spring context'.

       

      So, any ideas what's wrong here?

        • 1. Re: Embedded hornetq using spring (Chapter 43)
          Gazal KA Newbie

          Ok, I think I've figured this out.

           

          First the entry name in my hornetq-jms.xml file was '/ConnectionFactory' (includes a slash character).

          Also the inclusion of depends-on attribute for the bean was necessary.

           

          So the bean declaration is as follows:

           

           

          {code:xml}          <bean id="inVmJmsWriter" class="com.mycompany.utils.jms.JmsWriter" depends-on="embeddedJms">

                              <constructor-arg ref="/ConnectionFactory" />

                              <constructor-arg value="false" />

                              <constructor-arg value="#{T(javax.jms.Session).AUTO_ACKNOWLEDGE}" />

                              <constructor-arg ref="/queue/NotificationsQueue" />

                              <constructor-arg value="OBJECT" />

                              <qualifier value="inVmJmsWriter" />

                    </bean>

          {code}