全球onException的处理多个RouteBuilder类 [英] Global onException to handle multiple RouteBuilder classes
问题描述
我需要onException的,要在整个路线建设者我为了不重写每一个建设者的路线我创作的同一行全球。
我的异常处理目前的范围是特定路由建设者骆驼背景。我需要路由助洗剂类,r1和r2,使用相同onException的()。过程
当前工作onException的使用:
高清配置{ onException的(classOf [CustomException])。流程(exceptionProcessor)。
流程(doExtraProcess)
从(地址)。
流程(doSmth)。
流程(doSmthElse)
}
当我已经从configre方法onException的()线是在类级别如下所示:
onException的(classOf [CustomException])。流程(exceptionProcessor)。
流程(doExtraProcess) 高清配置{ 从(地址)。
流程(doSmth)。
流程(doSmthElse)
}
我得到这个错误:
org.apache.camel.FailedToCreateRouteException:这是造成失败
在创建路径route52:>>> onException的[[类CustomException] - >
[过程[空],过程[空]]]<<<在路线:
路线[从[直接:基因] - > [onException的[参考,因为...的必须
上指定:工艺[空]
致:java.lang.IllegalArgumentException异常:必须指定裁判
上:工艺[空]
块引用>由configure()方法,以所谓的解决方案首先,onException的()的需求。接下来,你可以使用继承来重复使用异常处理。只要创建一个父类RouteBuilder,把共同的异常处理的方法。然后让每个子类调用,在他们的配置常用的方法()方法...
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]
解决方案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类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!