当我使用Spring来收听JMS消息时,我收到上面的错误.
我想知道如何在JMS监听器中添加一个Errorhandler?
最佳答案
AbstractMessageListenerContainer
有一个财产:
<bean id="listener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="errorHandler" ref="someHandler"/>
<property name="destinationName" value="someQueue"/>
<property name="connectionFactory" ref="connectionFactory"/>
</bean>
其中someHandler是一个实现ErrorHandler
的bean:
@Service
public class SomeHandler implements ErrorHandler {
@Override
public void handleError(Throwable t) {
log.error("Error in listener", t);
}
}
不过请注意,根据documentation:
The default behavior of this message listener […] will log any such exception at the error level. […] However, if error handling is necessary, then any implementation of the ErrorHandler strategy may be provided to the setErrorHandler(ErrorHandler) method.
查看你的日志,也许已经记录了例外?
相关文章
- java - Rabbit消息监听器的执行失败,并且没有设置ErrorHandler.无法使用参数类型= [class [B],调用目标方法,
- java - JMS消息侦听器Weblogic的并发处理
- java - JMS侦听器中异常的JMS消息重新传递
- java - 如何知道侦听器是否在JMS中获取消息?
- 编写测试以验证jms侦听器中收到的消息(Spring-Boot)
- jms - Spring DefaultMessageListenerContainer - 侦听器不在Websphere MQ上读取消息
- ibm-mq - Websphere 7 Websphere MQ 7.X Spring集成JMS - 消息侦听器停止从队列中读取消息
- java - 如何临时禁用消息侦听器