[英]Spring JMS : Set ErrorHandler for @JmsListener annotated method
I am using a @JmsListener
annotated method listen to JMS messages as shown below. 我正在使用@JmsListener
注释的方法监听JMS消息,如下所示。
@JmsListener(destination="exampleQueue")
public void fetch(@Payload String message){
process(message);
}
When this method execution result in an exception, I got a warn log 当这个方法执行导致异常时,我得到了一个警告日志
Execution of JMS message listener failed, and no ErrorHandler has been set.
How do I set an ErrorHandler
to handle the case. 如何设置ErrorHandler
来处理大小写。 I am using spring boot 1.3.3.RELEASE 我正在使用spring boot 1.3.3.RELEASE
While using annotations like @EnableJms
, @JmsListener
etc to work with Spring JMS, the ErrorHandler can be set like this 使用@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
}
}
More details are available here : Annotation-driven listener endpoints 此处提供了更多详细信息: 注释驱动的侦听器端点
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.