如何在测试环境中禁用JMS spring listener

时间:2014-01-06 17:01:03

标签: java spring spring-mvc jms weblogic

我使用spring JMSTemplate连接到不同weblogic域上的队列。 我在Spring配置中连接了所有组件,如jndiTemplate,connectionfactory,destination等。 消息由MessageListener的简单实现处理。

一切正常。但是当我尝试部署目标不可用的此应用程序时,部署失败。这对我来说非常重要,因为我们在某些环境中没有JMS基础设施。
我尝试在所有组件上使用lookupOnStartup = false,并尝试根据环境变量将它们注入DMLC。但问题是,听众似乎并未启动。所有消息都留在队列中。

非常感谢任何帮助。

弹簧配置:

<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
        <props>
            <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
            <prop key="java.naming.provider.url">t3://wp2128.xyz.int:7001</prop>
            <prop key="java.naming.security.authentication">none</prop>
            <prop key="java.naming.security.principal"></prop>
            </props>    
    </property>
</bean>
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean" >
    <property name="jndiTemplate" ref="jndiTemplate" />
    <property name="jndiName" value="jms/connectionFactory" />
</bean>
<bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiTemplate" ref="jndiTemplate" />
    <property name="jndiName" value="jms/testQueue" />
</bean>


<bean id="simpleConsumer"
    class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="concurrentConsumers" value="5" />
    <property name="connectionFactory" ref="connectionFactory" />
    <property name="destination" ref="destination" />
    <property name="messageListener" ref="simpleMessageListener" />
</bean>

1 个答案:

答案 0 :(得分:0)

您可以将autoStartup设置为false。此属性值可以在属性文件中外部化。

<bean id="simpleConsumer"
    class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="concurrentConsumers" value="5" />
    <property name="connectionFactory" ref="connectionFactory" />
    <property name="destination" ref="destination" />
    <property name="messageListener" ref="simpleMessageListener" />
   <property name="autoStartup" value="false"/>
</bean>
相关问题