<from uri="sql:select * from params?dataSource=moodleDB"/>
异常:
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
我怎样才能抓住这个例外?
答案 0 :(得分:1)
通常从端点不倾向于抛出异常,我会尝试解决其他启动程序的问题,然后我会跟进异常处理程序。如果要重试,错误处理程序将从任何失败的步骤重试,并且您可以为不同的异常类型设置不同的行为。此错误处理程序将用于整个上下文,但您也可以在路由级别设置它们。可以在此处找到更多信息: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");
答案 1 :(得分:0)
您也可以使用其中一个错误处理程序。 可以在此处找到更多信息:http://camel.apache.org/error-handler.html
@Override
public void configure() throws Exception {
errorHandler(deadLetterChannel("direct:sqlErrorHandler"));
from("sql:select * from params?dataSource=moodleD")......
from("direct:sqlErrorHandler")
.log(LoggingLevel.ERROR, "The exception occurred: ${exception.message}").
.log(LoggingLevel.ERROR, "Exception stacktrace : ${exception.stacktrace}").
.log(LoggingLevel.INFO, "SQL operation error!");
}