问题描述
我需要创建 onException,以便在我拥有的整个路由构建器中保持全局性,以免为我创建的每个路由构建器重写同一行.我的异常处理程序的当前范围是特定路由构建器的骆驼上下文.我需要创建路由构建器类 r1 和 r2,以使用相同的 onException().process.
I need to make onException, to be global over the whole route builders I have in order not to rewrite the same line for every route builder I create .The current scope for my exception handler is a camel context for specific route builder . I need to make route builder classes ,r1 and r2, to use the same onException().process.
我使用的当前处理异常:
The current working onException I use :
def configure {
onException(classOf[CustomException]).process(exceptionProcessor).
process(doExtraProcess)
from(address).
process(doSmth).
process(doSmthElse)
}
当我将 onException() 行从 configre 方法移动到类级别时,如下所示:
When I have moved the onException() line from configre method to be on the class level like the following :
onException(classOf[CustomException]).process(exceptionProcessor).
process(doExtraProcess)
def configure {
from(address).
process(doSmth).
process(doSmthElse)
}
我收到此错误:
引起:org.apache.camel.FailedToCreateRouteException: Failed to在以下位置创建路由 route52:>>> OnException[[class CustomException] ->[进程[空],进程[空]]] <<<途中:Route[[From[direct:locus]] -> [OnException[[... 因为 ref 必须是指定于:process[null]
Caused by: java.lang.IllegalArgumentException: ref must be specified在:进程[空]
Caused by: java.lang.IllegalArgumentException: ref must be specified on: process[null]
推荐答案
首先,需要通过 configure() 方法调用 onException().接下来,您可以仅使用继承来重用异常处理.只需创建一个父 RouteBuilder 类并将常见的异常处理放在一个方法中.然后让每个子类在它们的 configure() 方法中调用那个通用方法...
First, onException() needs to called by the configure() method. Next, you can just use inheritance to reuse exception handling. Just create a parent RouteBuilder class and put common exception handling in a method. Then have each subclass call that common method in their configure() method...
这篇关于全局 onException 处理多个 RouteBuilder 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!