代码之家  ›  专栏  ›  技术社区  ›  Mauli

当我的webapp在JBOSS 6.0中启动时,我如何确保大黄蜂队列在那里?

  •  2
  • Mauli  · 技术社区  · 14 年前

    以前的标题是:

    如何使用Spring获取对JBOSS 6中队列的JNDI引用?

    我配置了这样一个JMS队列,它位于mytopic-hornetq-JMS.xml文件中:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration xmlns="urn:hornetq"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
        <topic name="mytopic">
            <entry name="mytopic"/>
        </topic>
    </configuration>
    

    我的applicationContext.xml如下所示:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/jee 
    http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
    
        <jee:jndi-lookup id="jmsConnectionFactory" jndi-name="java:/JmsXA" />
        <jee:jndi-lookup id="jmsDestination" jndi-name="mytopic" expected-type="javax.jms.Topic" />
    </beans>
    

    这是使用JMX控制台org.jboss.naming.JNDIView的输出:

      +- UserTransactionSessionFactory (proxy: $Proxy103 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
      +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
      +- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory)
      +- SecureDeploymentManager (class: org.jnp.interfaces.NamingContext)
      |   +- remote[link -> DeploymentManager] (class: javax.naming.LinkRef)
      +- SecureManagementView (class: org.jnp.interfaces.NamingContext)
      |   +- remote[link -> ManagementView] (class: javax.naming.LinkRef)
      +- mytopic (class: org.hornetq.jms.client.HornetQTopic)
      +- DeploymentManager (class: org.jboss.aop.generatedproxies.AOPProxy$4)
      +- XAConnectionFactory (class: org.hornetq.jms.client.HornetQConnectionFactory)
      +- ProfileService (class: org.jboss.aop.generatedproxies.AOPProxy$2)
      +- SecureProfileService (class: org.jnp.interfaces.NamingContext)
      |   +- remote[link -> ProfileService] (class: javax.naming.LinkRef)
      +- queue (class: org.jnp.interfaces.NamingContext)
      |   +- DLQ (class: org.hornetq.jms.client.HornetQQueue)
      |   +- ExpiryQueue (class: org.hornetq.jms.client.HornetQQueue)
      +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
      +- ConnectionFactory (class: org.hornetq.jms.client.HornetQConnectionFactory)
      +- jmx (class: org.jnp.interfaces.NamingContext)
      |   +- invoker (class: org.jnp.interfaces.NamingContext)
      |   |   +- RMIAdaptor (class: javax.management.MBeanServerConnection)
      |   +- rmi (class: org.jnp.interfaces.NamingContext)
      |   |   +- RMIAdaptor (class: javax.management.MBeanServerConnection)
      +- BeanValidatorFactories (class: org.jnp.interfaces.NamingContext)
      +- TomcatAuthenticators (class: java.util.Properties)
      +- XAThroughputConnectionFactory (class: org.hornetq.jms.client.HornetQConnectionFactory)
      +- ManagementView (class: org.jboss.aop.generatedproxies.AOPProxy$3)
      +- ThroughputConnectionFactory (class: org.hornetq.jms.client.HornetQConnectionFactory)
    

    在我的书中,这个主题被绑定到JNDI名称“my topic”

    不过,春投

    18:45:29,636 ERROR [ContextLoader] Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsDestination': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: mytopic not bound
    ...
    Caused by: javax.naming.NameNotFoundException: mytopic not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:771) [:5.0.5.Final]
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:779) [:5.0.5.Final]
      at org.jnp.server.NamingServer.getObject(NamingServer.java:785) [:5.0.5.Final]
      at org.jnp.server.NamingServer.lookup(NamingServer.java:443) [:5.0.5.Final]
    

    更新

    看起来,查找JNDI引用实际上并不是问题,但实际上,在应用程序启动时并没有配置hornet队列。

    如果我稍后再部署应用程序,它将运行得很好,因为此时大黄蜂排队 已配置。

    是否有方法指定应用程序在所有队列都启动之前不会启动,或者jboss是否有一个配置选项来保持部署,直到其他队列启动为止?

    3 回复  |  直到 14 年前
        1
  •  2
  •   Konstantin    14 年前

    我成功地使用了Jboss 4.2中的“依赖”机制。使用它,您可以指定某些内容依赖于其他内容(使用xml描述符或对于ejb3,您可以使用注释)。这是一个链接 started

        2
  •  0
  •   Grzegorz Oledzki    14 年前

    如果您添加了 java:/ 前缀(与JmsXA相同)?即

    <jee:jndi-lookup id="jmsDestination" jndi-name="java:/mytopic" expected-type="javax.jms.Topic" />
    

    顺便说一句,我看不出 JmsXA 在JNDI转储中的名称。你可能也有问题。

        3
  •  0
  •   Grzegorz Oledzki    14 年前

    我没用过霍内特,我只是为了你的问题读一下 tutorial on setting up Spring together with HornetQ . 那里有一个关于设置 jndi.properties . 这可能是为了确保HornetQ将其内容注册到JBoss JNDI上下文中。

    你确定你有一个像他们建议的那样的文件并且放得正确吗?