Spring JMS:为@JmsListener 注释方法设置错误处理程序

Spring JMS : Set ErrorHandler for @JmsListener annotated method

我正在使用 @JmsListener 注释方法来侦听 JMS 消息,如下所示。

@JmsListener(destination="exampleQueue")  
public void fetch(@Payload String message){  
    process(message);  
}

当这个方法执行出现异常时,我得到一个警告日志

Execution of JMS message listener failed, and no ErrorHandler has been set.

如何设置一个 ErrorHandler 来处理这种情况。我正在使用 spring boot 1.3.3.RELEASE

在使用 @EnableJms@JmsListener 等注解与 Spring JMS 一起工作时,可以像这样设置 ErrorHandler

@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(ConnectionFactory connectionFactory, ExampleErrorHandler errorHandler) {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);
    factory.setErrorHandler(errorHandler);
    return factory;
}

@Service
public class ExampleErrorHandler implements ErrorHandler{   
    @Override
    public void handleError(Throwable t) {
        //handle exception here
    }
}

此处提供更多详细信息:Annotation-driven listener endpoints