使用Spring与JNDI查找配置ActiveMQ

使用Spring与JNDI查找配置ActiveMQ,spring,activemq,Spring,Activemq,各位-我有一个Spring3.1、ActiveMQ5.8和Tomcat7设置 与JNDI查找相比,在Spring中配置工厂和队列有什么优势吗 <amq:connectionFactory id="connectionFactory" brokerURL="tcp://localhost:61616"/> <amq:queue id="queueOne" physicalName="TestQueueOne"/> <amq:queue id="queueTwo" ph

各位-我有一个Spring3.1、ActiveMQ5.8和Tomcat7设置

与JNDI查找相比,在Spring中配置工厂和队列有什么优势吗

<amq:connectionFactory id="connectionFactory" brokerURL="tcp://localhost:61616"/>
<amq:queue id="queueOne" physicalName="TestQueueOne"/>
<amq:queue id="queueTwo" physicalName="TestQueueTwo"/>

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="connectionFactory" />
</bean>

META-INF/context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context>   
<Resource 
    name="jms/ConnectionFactory" 
    auth="Container"
    type="org.apache.activemq.ActiveMQConnectionFactory" 
    description="JMS Connection Factory"
    factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
    brokerURL="tcp://localhost:61616" />

<Resource 
    name="jms/QueueOne" 
    auth="Container"
    type="org.apache.activemq.command.ActiveMQQueue" 
    factory="org.apache.activemq.jndi.JNDIReferenceFactory"
    physicalName="TestQueueOne" />

<Resource 
    name="jms/QueueTwo" 
    auth="Container"
    type="org.apache.activemq.command.ActiveMQQueue" 
    factory="org.apache.activemq.jndi.JNDIReferenceFactory"
    physicalName="TestQueueTwo" />
</Context>  


我想知道一种方法是否比另一种“更好”

根据您当前使用Tomcat的设置,可能Spring配置是一种选择。如果您打算改用成熟的应用服务器,例如JBoss,那么JNDI可能会更好,因为您可以利用集群JNDI实现应用服务器提供的高可用性: