2013-04-05 76 views
0

在本地,我的應用程序可以很好地連接到內置的Netty ConnectionFactory,並且在啓動或發送主題消息時沒有問題。我的本地盒子是獨立的JBoss 5.1和獨立的HornetQ。無法使用Spring 3連接到JBoss 5中的HornetQ連接工廠

然而,部署到我們的開發服務器時(運行羣集的JBoss 5.1和羣集HornetQ的),我無法連接,得到以下堆棧跟蹤:

ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/eShowroom]] (main) Exception sending context initialized event to listener instance of cla>\ss org.springframework.web.context.ContextLoaderListener 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'topicConnectionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: ConnectionFactory not bound 

我試圖使用默認,內置netty連接器,除了我自己的JMS主題外沒有額外的配置。我相對不知道DEV服務器設置,因爲它超出了我的控制範圍,並且相當於黑箱。

的applicationContext.xml(在$JBOSS_HOME/server/default/deploy/application.war/WEB-INF):

<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate"> 
     <property name="environment"> 
      <props> 
       <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop> 
       <prop key="java.naming.provider.url">jnp://${jboss.bind.address:localhost}:1099</prop> 
       <prop key="java.naming.factory.url.pkgs">org.jboss.naming</prop> 
      </props> 
     </property> 
    </bean> 

    <bean id="topicConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"> 
     <property name="jndiTemplate" ref="jndiTemplate"></property> 
     <property name="jndiName" value="/ConnectionFactory"></property> 
    </bean> 

    <bean id="cacheTopic" class="org.springframework.jndi.JndiObjectFactoryBean"> 
     <property name="jndiTemplate" ref="jndiTemplate"></property> 
     <property name="jndiName" value="/topic/myCacheTopic"></property> 
    </bean> 

    <bean id="jmsDestinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver"> 
     <property name="jndiTemplate" ref="jndiTemplate"/> 
     <property name="cache" value="true"/> 
    </bean> 

    <bean id="messageSendTemplate" class="org.springframework.jms.core.JmsTemplate"> 
     <property name="connectionFactory" ref="topicConnectionFactory"/> 
     <property name="destinationResolver" ref="jmsDestinationResolver"/> 
     <property name="pubSubDomain" value="true"/> 
    </bean> 

將hornetq-jms.xml文件(在$JBOSS_HOME/server/default/deploy/hornetq.sar

<connection-factory name="NettyConnectionFactory"> 
     <xa>true</xa> 
     <connectors> 
     <connector-ref connector-name="netty"/> 
     </connectors> 
     <entries> 
     <entry name="/ConnectionFactory"/> 
     <entry name="/XAConnectionFactory"/> 
     </entries> 
    </connection-factory> 

    <connection-factory name="NettyThroughputConnectionFactory"> 
     <xa>true</xa> 
     <connectors> 
     <connector-ref connector-name="netty-throughput"/> 
     </connectors> 
     <entries> 
      <entry name="/ThroughputConnectionFactory"/> 
      <entry name="/XAThroughputConnectionFactory"/> 
     </entries> 
    </connection-factory> 

    <connection-factory name="InVMConnectionFactory"> 
     <xa>true</xa> 
     <connectors> 
     <connector-ref connector-name="in-vm"/> 
     </connectors> 
     <entries> 
     <entry name="java:/ConnectionFactory"/> 
     <entry name="java:/XAConnectionFactory"/> 
     </entries> 
    </connection-factory> 

本地和DEV之間的唯一區別,我可以很容易地spot位於hornetq-configuration.xml中。

DEV hornetq-configuration.xml文件(相同的路徑將hornetq-jms.xml文件)

<broadcast-groups> 
     <broadcast-group name="bg-group1"> 
     <group-address>${hornetq.broadcast.bg-group1.address:231.7.7.7}</group-address> 
     <group-port>${hornetq.broadcast.bg-group1.port:9876}</group-port> 
     <broadcast-period>5000</broadcast-period> 
     <connector-ref>netty</connector-ref> 
     </broadcast-group> 
    </broadcast-groups> 

    <discovery-groups> 
     <discovery-group name="dg-group1"> 
     <group-address>${hornetq.discovery.dg-group1.address:231.7.7.7}</group-address> 
     <group-port>${hornetq.discovery.dg-group1.port:9876}</group-port> 
     <refresh-timeout>10000</refresh-timeout> 
     </discovery-group> 
    </discovery-groups> 

    <cluster-connections> 
     <cluster-connection name="my-cluster"> 
     <address>jms</address> 
     <connector-ref>netty</connector-ref> 
      <discovery-group-ref discovery-group-name="dg-group1"/> 
     </cluster-connection> 
    </cluster-connections> 
+0

你試過 <屬性名=「jndiName」值=「連接工廠」> 也就是說,沒有前導「/」之名。 – 2013-06-04 16:57:42

回答

0

所以,事實證明,無論出於何種原因,這是在集羣環境中的計時問題。需要連接工廠的bean只是被迫等到其他所有東西都啓動並運行之後才啓動。