我正在使用彈簧集成的錯誤通道捕獲框架中的異常。但是在同一類型的兩個通道中,一個拋出的異常由錯誤處理程序接收,而另一個則不是。彈簧集成錯誤通道不會收到所有異常
<int:gateway id="myGateway" service-interface="com.si.MyGateway" request-
channel="myRequestChannel" error-channel="errorHandlingChannel">
<!-- Redirects exceptions to error-channel -->
<int:chain input-channel="myRequestChannel" output-channel="lastChannel">
<int:header-enricher>
<int:error-channel ref="errorHandlingChannel">
<int:header-enricher>
<int:service-activator ref="testActivator1"
method="generateException" requires-reply="true" />
</int:chain>
<!-- Does not redirect exceptions to error-channel -->
<int:chain input-channel="lastChannel" output-
channel="nullChannel">
<int:header-enricher>
<int:error-channel ref="errorHandlingChannel">
<int:header-enricher>
<int:service-activator ref="testActivator2"
method="generateException" requires-reply="true" />
<int:filter ref="myFilter" discard-channel="nullChannel" />
<int:service-activator ref="testActivator3"
method="generateException" requires-reply="true" />
<int:filter ref="myFilter" discard-channel="nullChannel" />
</int:chain>
<int:service-activator input-channel="errorHandlingChannel"
ref="errorHandler" method="handle" />
的的ErrorHandler的處理方法接受MessagingException。當我從myRequestChannel拋出異常時,它由errorHandler接收,但是當從testActivator2或testActivator3拋出相同的異常時,它根本沒有到達errorHandler。
兩個通道被定義爲異步信道:
<int:channel>
<int:queue capacity="10">
</int:channel>
在調試,我發現,所有的方法異常被拋出並按照一個鏈通過彈簧的類時,一個內部類最終拋出MessagingException,但最後兩個激活器的異常不會到達處理程序。
可能是什麼原因?
這可以解決您的問題http://forum.spring.io/forum/spring-projects/integration/72082-error-channel-service-activator – Rjiuk
謝謝,但我所有的渠道是異步的,所以解決方案中提到該鏈接已經實施,但無濟於事。 – sajinket
你不需要'header-richher's - 網關會自動設置'errorChannel'頭。在你的配置中沒有任何明顯的東西。我建議你爲'org.springframework.integration'啓用DEBUG日誌記錄;如果你無法從日誌中找出它,請用日誌編輯你的問題。 –