在JBoss EAP 6.2.0中通过JNDI访问本地HornetQ连接工厂

3
我已经在 JBoss 中部署了一个 Web 应用程序(jms-api.war),我想通过 JNDI 从中获取一个 JMS 连接工厂,是否可以不进行任何配置 (像这样)? 我尝试使用没有任何配置的 JNDI:

我的连接工厂在 standalone.xml 中:

<jms-connection-factories>
    <connection-factory name="InVmConnectionFactory">
        <connectors>
            <connector-ref connector-name="in-vm"/>
        </connectors>
        <entries>
            <entry name="java:/ConnectionFactory"/>
        </entries>
    </connection-factory>
</jms-connection-factories>

在我的应用程序中,我有这个Spring Bean来访问连接工厂(在嵌入式HornetQ中运行的测试中它有效):

<bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="/ConnectionFactory" />
    <property name="resourceRef" value="true"/>
</bean>

在jboss启动过程中,我遇到了这个错误,该如何解决?
JBAS014775:    New missing/unsatisfied dependencies:
      service jboss.naming.context.java.jboss.resources.jms.ConnectionFactory (missing) dependents: [service jboss.naming.context.java.module.jms-api.jms-api.env.jms.ConnectionFactory] 

JBoss日志(HornetQ启动部分):

11:00:32,689 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 50) HQ221000: live server is starting with configuration HornetQ Configuration (clustered=false,backup=false,sharedStore=true,journalDirectory=C:\Users\Mojtaba\workspace-hornetq\build\appserver\jboss\standalone\data\../../../hornetqdata/journal,bindingsDirectory=C:\Users\Mojtaba\workspace-hornetq\build\appserver\jboss\standalone\data\../../../hornetqdata/bindings,largeMessagesDirectory=C:\Users\Mojtaba\workspace-hornetq\build\appserver\jboss\standalone\data\../../../hornetqdata/large-message,pagingDirectory=C:\Users\Mojtaba\workspace-hornetq\build\appserver\jboss\standalone\data\../../../hornetqdata/paging)
11:00:32,691 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 50) HQ221006: Waiting to obtain live lock
11:00:32,723 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 50) HQ221013: Using NIO Journal
11:00:32,840 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 50) HQ221034: Waiting to obtain live lock
11:00:32,841 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 50) HQ221035: Live Server Obtained live lock
11:00:33,041 INFO  [org.jboss.as.remoting] (MSC service thread 1-1) JBAS017100: Listening on 127.0.0.1:9999
11:00:33,777 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 50) HQ221020: Started Netty Acceptor version 3.6.6.Final-redhat-1-fd3c6b7 0.0.0.0:5445 for CORE protocol
11:00:33,779 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 50) HQ221007: Server is now live
11:00:33,780 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 50) HQ221001: HornetQ Server version 2.3.12.Final (2.3.12, 123) [c0d4ec44-d8d5-11e3-afd6-5372513ac770] 
11:00:33,786 INFO  [org.hornetq.jms.server] (ServerService Thread Pool -- 50) HQ121005: Invalid "host" value "0.0.0.0" detected for "netty" connector. Switching to "Mojtaba-PC". If this new address is incorrect please manually configure the connector to use the proper one.
11:00:33,811 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 50) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/RemoteConnectionFactory
11:00:33,812 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 50) JBAS011601: Bound messaging object to jndi name java:/RemoteConnectionFactory
11:00:33,815 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 52) JBAS011601: Bound messaging object to jndi name java:/ConnectionFactory
11:00:33,816 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 51) HQ221003: trying to deploy queue jms.queue.testQueue
11:00:34,115 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 51) JBAS011601: Bound messaging object to jndi name java:/queue/testQueue
11:00:34,116 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 51) JBAS011601: Bound messaging object to jndi name java:jboss/exported/queues/testQueue
11:00:34,195 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 27) JBAS018559: Deployed "jms-api.war" (runtime-name : "jms-api.war")
11:00:34,199 INFO  [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014775:    New missing/unsatisfied dependencies:
      service jboss.naming.context.java.jboss.resources.jms.ConnectionFactory (missing) dependents: [service jboss.naming.context.java.module.jms-api.jms-api.env.jms.ConnectionFactory] 

(jboss eap 6.2.0, hornetq 2.3.12.Final)

3个回答

3

虽然我还没有使用过v6.2,但您可以尝试以下方法。错误是无法通过JNDI树找到连接工厂。因此,请在已列出的条目中添加以下内容:

<entries>
  <entry name="java:/ConnectionFactory"/>
  <!-- Add this -->
  <entry name="java:jboss/exported/ConnectionFactory"/>
</entries>

将连接器引用从in-vm更改为netty


我仍然有同样的问题,我应该在我的应用程序中更改<property name="jndiName" value="/ConnectionFactory" />的值吗? - Arya

2

我在消息子系统中定义了这个连接工厂:

<connection-factory name="RemoteConnectionFactory">
    <connectors>
    <connector-ref connector-name="netty"/>
    </connectors>
    <entries>
        <entry name="java:jboss/exported/jms/ConnectionFactory"/>
    </entries>
</connection-factory>

在我的Web应用程序Spring Bean配置中(jndiName应该以java:/开头):

<bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:/jboss/exported/jms/ConnectionFactory" />
    <property name="lookupOnStartup" value="false"/>
    <property name="proxyInterface" value="javax.jms.ConnectionFactory"/>
</bean>

而且不需要在web.xml中进行任何更改或配置(例如,不需要在web.xml中使用resource-ref)!


2
最简单的解决方案是更改您的bean配置:
<bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:/ConnectionFactory" />
    <property name="resourceRef" value="false"/>
</bean>

如果resourceRef为true,则Spring会尝试查找"java:comp/env/ConnectionFactory"(或者甚至是"java:comp/env//ConnectionFactory"),因为这是所有JavaEE容器(不仅仅是JBoss)正确的资源引用格式。
如果您想使用资源引用,必须在您的web.xml文件中声明它们,并在jboss-web.xml文件中映射它们。
当您尝试编写必须在不同的JavaEE服务器实现之间可移植的代码时,您通常会这样做。它们都有自己的jboss-web.xml版本,用于在常量资源引用名称和服务器中的物理资源名称之间进行映射。

我按照你说的更改了jndiName和resourceRef,但是仍然出现相同的错误。 - Arya

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接