mysql - 我如何处理 CAMEL jdbc 连接异常?

标签 mysql exception jdbc apache-camel

 <from uri="sql:select * from params?dataSource=moodleDB"/>

异常(exception):

    org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 
** BEGIN NESTED EXCEPTION ** 
java.net.ConnectException
MESSAGE: Connection refused: connect
STACKTRACE:
java.net.ConnectException: Connection refused: connect

我怎样才能捕捉到这个异常?

最佳答案

通常从端点不会抛出异常,我会尝试使用其他东西来启动您的程序,然后我会跟进一个异常处理程序。如果您想要重试,错误处理程序将从失败的任何步骤重试,并且您可以为不同的异常类型设置不同的行为。此错误处理程序将用于您的整个上下文,但您也可以在路由级别设置它们。可以在此处找到更多信息:http://camel.apache.org/error-handling-in-camel.html

onException(Exception.class)
    .handled(true)
    .log(LoggingLevel.ERROR, "${exception.stackTrace}")
    .stop();

from("timer://RunOnStartupOnceTimer?repeatCount=1")
    .to("sql:select * from params?dataSource=moodleDB")
    .to("moreProcessing");

关于mysql - 我如何处理 CAMEL jdbc 连接异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33034704/

相关文章:

java - 仅当没有抛出异常时如何执行代码块

c# - WPF 全局异常处理程序

java - 有没有办法在 Java 中找出数据库游标是否打开?

postgresql - kafka-connect-jdbc 不从源中获取连续的时间戳

php - SilverStripe - 自定义分面搜索导航

php将csv文件导入数据库

mysql - 使用 socket.io 和 mysql session 存储进行 Node.js 集群

c++ - 有没有办法_get_UnhandledExceptionFilter?

Mysql数据库设计建议

java - 与 DAO 模式的对称关系