日期:2014-05-18  浏览次数:20725 次

Spring JMS监听器问题
<!-- 消息监听容器 -->  
<bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">  
    <property name="concurrentConsumers" value="2" />  
    <property name="connectionFactory" ref="connectionFactory" />    
    <property name="destination" ref="destination" />
    <property name="messageListener" ref="messageReceiver" />
    <property name="pubSubNoLocal" value="false"></property>
</bean>
  

如果我的activeMQ没有打开,就一直报这样的错:

    警告: Setup of JMS message listener invoker failed for destination 'queue://emailQueue' - trying to recover. Cause: Connection reset
2014-2-8 16:20:49 org.springframework.jms.listener.DefaultMessageListenerContainer refreshConnectionUntilSuccessful
严重: Could not refresh JMS Connection for destination 'queue://emailQueue' - retrying in 5000 ms. Cause: Error while attempting to retrieve a connection from the pool; nested exception is javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused: connect


怎么不让它报这个错啊?每次开发都把MQ打开,比较麻烦
------解决方案--------------------
既然你用了jms监听,说明你是要从jms获取数据,当然要连接mq了...
想不做默认连接的话,一个办法是你不要引用这个bean,默认情况下,bean是懒加载的,如果你没有引用他,那是不会启动数据监听的
如果一定要引用的又要保持模块独立的话,使用接口编程,让这个bean成为一个接口,实际实现与开发实现分离,开发实现有空方法通过编译就行