2

以前的标题是:

如何使用 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 名称“mytopic”

尽管如此,Spring 还是会抛出

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 的配置选项在其余部分启动之前保持部署?

4

3 回答 3

2

我已经成功地使用了 Jboss 4.2 中的“依赖”机制。有了它,您可以指定某些东西依赖于其他东西(使用 xml 描述符或对于 ejb3,您可以使用注释)。这是一个让你开始的链接

于 2010-12-15T20:38:20.497 回答
0

如果添加java:/前缀(与 JmsXA 相同)会怎样?IE

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

JmsXA顺便说一句,我在您的 JNDI 转储中没有看到任何在名称下定义的内容。你可能也有这个问题。

于 2010-11-24T20:51:09.370 回答
0

我没有使用 HornetQ,我只是为了您的问题阅读了有关设置 Spring 和 HornetQ 的教程。那里有一个关于设置的部分jndi.properties。这可能是为了确保 HornetQ 将其内容注册到 JBoss JNDI 上下文中。

您确定您有他们建议的文件并且放置正确吗?

于 2010-11-25T09:03:45.537 回答