我在JBoss中部署了一个Web应用程序(jms-api.war),我希望通过它从JNDI获得一个JMS连接工厂,是否可以不进行任何配置(like this)?我试图在没有任何配置的情况下使用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)
答案 0 :(得分:3)
虽然我还没有使用v6.2,但你可以试试这个。该错误无法通过JNDI树找到您的连接工厂。因此,请在已列出的条目中添加以下内容:
<entries>
<entry name="java:/ConnectionFactory"/>
<!-- Add this -->
<entry name="java:jboss/exported/ConnectionFactory"/>
</entries>
将连接器ref从in-vm更改为netty
答案 1 :(得分: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将尝试查找&#34; java:comp / env / ConnectionFactory&#34;,(或者甚至&#34; java:comp / env // ConnectionFactory&#34;) ,因为这是所有JavaEE容器(不仅仅是JBoss)的正确资源引用。
如果要使用资源引用,则必须在web.xml文件中声明它们并将它们映射到jboss-web.xml文件中。
当您尝试编写必须可在不同JavaEE服务器实现之间移植的代码时,通常会执行此操作。它们都有自己的jboss-web.xml变体,用于映射服务器中的常量资源引用名称和物理资源名称。
答案 2 :(得分:2)
我在我的消息传递子系统上定义了这个连接工厂:
<connection-factory name="RemoteConnectionFactory">
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="java:jboss/exported/jms/ConnectionFactory"/>
</entries>
</connection-factory>
并在我的webapp 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)!