Global erroChannel service activator not invoked

2019-08-08 04:19发布

问题:

I have written an service activator for global errorChannel.

<!-- global default exception handler--> 
<int:service-activator input-channel="errorChannel" 
      auto-startup="true" ref="defaultExeptionHandler" >
</int:service-activator>

Test class

@Test
public void testTradeAcceptanceFlow() throws Exception {
    throw new FileNotFoundException();
}

Since I am explicitly throwing error, I was hoping that this would get caught in the global error channel and will in turn call my handler, which it is not doing. Any idea as to why?

回答1:

An exception is wrapped to the ErrorMessage and sent to the global (default) errorChannel if you have some async handoff in your flow.

Please, see more info in the Reference Manual.

There is a note:

The most important thing to understand here is that the messaging-based error handling will only apply to Exceptions that are thrown by a Spring Integration task that is executing within a TaskExecutor. This does not apply to Exceptions thrown by a handler that is operating within the same thread as the sender (e.g. through a DirectChannel as described above).

Many guys are missing this standard Java try...catch bahaviour in the Spring Integration and try to treat everything with that errorCnannel.

Regarding your test-method. It is fully does not make sense and does not get deal with any Spring Integration stuff.