是Spring@TransactionalEventListener的某种错误处理程序
最近,我一直在测试Spring中新的是Spring@TransactionalEventListener的某种错误处理程序,spring,error-handling,event-listener,Spring,Error Handling,Event Listener,最近,我一直在测试Spring中新的@TransactionalEventListener的使用。 但我找不到一个好方法来处理事件侦听器方法中可能抛出的错误。 顺便说一下,我测试过的@EventListener注释没有相同的行为:RunTimeException按预期抛出 例如,我希望避免编写try-catch以了解错误: @Component public class PairingEventListener { ... @TransactionalEventListene
@TransactionalEventListener
的使用。
但我找不到一个好方法来处理事件侦听器方法中可能抛出的错误。
顺便说一下,我测试过的@EventListener
注释没有相同的行为:RunTimeException
按预期抛出
例如,我希望避免编写try-catch以了解错误:
@Component
public class PairingEventListener {
...
@TransactionalEventListener
@Transactional
public void onPairingSuccessEvent(PairingSuccessEvent event) {
try {
// some code here that could throws runtime error
} catch (Exception e) {
logger.error(e);
}
}
}
有人知道是否有一种方法可以实现与JmsErrorHandler
相当的东西,但是使用SpringApplicationEvent
@Autowired
DefaultJmsListenerContainerFactory jmsListenerContainerFactory;
...
jmsListenerContainerFactory.setErrorHandler(new JmsErrorHandler());
谢谢