如何从jdbc-inbound-channel-adapter中捕获异常?

时间:2019-01-29 10:46:24

标签: java jdbc spring-integration

是否可以从jdbc-inbound-channel-adapter捕获异常(例如,查询执行期间数据库出现问题)?
例如。在http-outbound-gateway中,可以使用通过error-handler属性声明的错误处理程序。
多谢建议。

1 个答案:

答案 0 :(得分:1)

jdbc-inbound-channel-adapter完全基于JdbcPollingChannelAdapter及其SourcePollingChannelAdapter包装器,用于“硬”轮询逻辑。

我很确定您已经为上述<poller>或全局提供了jdbc-inbound-channel-adapter配置。

那个有这个选项:

   <xsd:attribute name="error-channel" type="xsd:string">
        <xsd:annotation>
            <xsd:documentation><![CDATA[
                Identifies channel that error messages will be sent to if a failure occurs in this
                poller's invocation. To completely suppress Exceptions, provide a
                reference to the "nullChannel" here.
            ]]></xsd:documentation>
        </xsd:annotation>
    </xsd:attribute>

因此,如果在轮询数据库期间出现一些错误,它将被包装到ErrorMessage中并发送到已配置的error-channel中。如果未提供,将使用全局errorChannel bean。

有关更多信息,请参见参考手册中的“错误处理”一章:https://docs.spring.io/spring-integration/docs/current/reference/html/configuration.html#namespace-errorhandler

相关问题