一尘不染

JNDI不适用于HornetQ和tomcat

tomcat

我正在尝试在Tomcat上使用hornetq运行JMS应用程序!我试图按照这篇文章。我将jndi.properties放在客户端类路径中;jndi.properties:

java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory 
java.naming.factory.url.pkgs=org.apache.naming

我将这些依赖项添加到pom.xml中:

<dependency> 
    <groupId>tomcat</groupId> 
    <artifactId>naming-factory</artifactId> 
    <version>5.5.23</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
     <groupId>tomcat</groupId> 
     <artifactId>naming-resources</artifactId> 
     <version>5.5.23</version> 
     <scope>test</scope> 
 </dependency>

我的JMSspring豆:

<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
        <property name="environment">
            <props>
                <prop key="java.naming.factory.initial">org.apache.naming.java.javaURLContextFactory</prop>
                <prop key="java.naming.factory.url.pkgs">org.apache.naming</prop>
            </props>
        </property>
    </bean>

<!-- Connection Factory -->
<bean id="hornetqConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiTemplate" ref="jndiTemplate"/>
    <property name="jndiName" value="/ConnectionFactory" />
</bean>

<!-- Destinations -->
<bean id="annotationDeleteCommandDestination" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiTemplate" ref="jndiTemplate"/>
    <property name="jndiName" value="/queue/command/annotation/deleteQueue" />
</bean>

我正在使用HornetQ默认服务器(独立,非群集)

hornetq-jms.xml:

<queue name="annotationDeleteCommandQueue">
    <entry name="/queue/command/annotation/deleteQueue"/>
</queue>

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

但是当我启动tomcat时出现此错误:

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hornetqConnectionFactory' defined in ServletContext resource [/WEB-INF/classes/config/spring/applicationContext-jms.xml]: 
Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name ConnectionFactory is not bound in this Context .........

怎么了?我应该将任何jar文件放在tomcat类路径中吗?(哪个jar?)我应该在tomcat配置中放入队列和连接工厂定义吗?(如何?)我可以在tomcat中禁用JNDI并改用hornetq独立JNDI吗?


阅读 239

收藏
2020-06-16

共1个答案

一尘不染

我通过修改jndiTemplate(使用jboss命名)并将jnp-client.jar添加到客户端类路径来解决了这个问题:

<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.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop>
            <prop key="java.naming.provider.url">jnp://localhost:1099</prop>
        </props>
    </property>
</bean>
2020-06-16