当我使用 Spring 监听 JMS 消息时,我收到了上述错误。
我想知道如何将 Errorhandler 添加到 JMS 监听器中?
最佳答案
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 - JMS消息监听器执行失败,没有设置ErrorHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8922532/