处理多个 RouteBuilder 类的全局 onException
我需要制作 onException,使其在我拥有的整个路线构建器中具有全局性,以免为我创建的每个路线构建器重写同一行。 我的异常处理程序的当前范围是特定路由构建器的骆驼上下文。我需要创建路由构建器类 r1 和 r2,以使用相同的 onException().process。
我使用的当前工作 onException :
def configure {
onException(classOf[CustomException]).process(exceptionProcessor).
process(doExtraProcess)
from(address).
process(doSmth).
process(doSmthElse)
}
当我将 onException() 行从 configre 方法移动到类级别时,如下所示:
onException(classOf[CustomException]).process(exceptionProcessor).
process(doExtraProcess)
def configure {
from(address).
process(doSmth).
process(doSmthElse)
}
我收到此错误:
原因:org.apache.camel.FailedToCreateRouteException:失败 创建路线route52:>> OnException[[类 CustomException] -> [进程[null],进程[null]]] <<<路线中: 路线[[From[direct:locus]] -> [OnException[[...因为 ref 必须是 指定于:process[null]
引起:java.lang.IllegalArgumentException:必须指定 ref 上:进程[null]
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)
}
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)
}
I got this error :
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to
create route route52 at: >>> OnException[[class CustomException] ->
[process[null], process[null]]] <<< in route:
Route[[From[direct:locus]] -> [OnException[[... because of ref must be
specified on: process[null]Caused by: java.lang.IllegalArgumentException: ref must be specified
on: process[null]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,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...