我有10条骆驼路线,如下所示
@AllArgsConstructor
public class MyCamelRoute extends RouteBuilder {
/**
* {@inheritDoc}
*/
@Override
public void configure() throws Exception {
}
}
MyCamelRoute上方是使用以下代码创建的,它将骆驼路径加载到弹簧容器中
@Bean("myCamelRoute")
public RouteBuilder createMyCamelRoute () {
return new MyCamelRoute();
}
现在,我需要在骆驼上下文中使用全局异常处理程序-覆盖所有路由。
答案 0 :(得分:2)
Java DSL的全局范围是每个RouteBuilder实例,因此,如果要在多个RouteBuilder类之间共享,请创建一个基本的抽象RouteBuilder类,并将错误处理逻辑放入其configure方法中。然后扩展此类,并确保对super.configure()进行分类。我们只是在使用Java继承技术。
换句话说,BaseRouteBuilder类将是:
"AzureAdB2C": {
"Instance": "https://.b2clogin.com/tfp/",
"ClientId": "clientid",
"CallbackPath": "/signin-oidc",
"Domain": ".onmicrosoft.com",
"ClientSecret": "",
"SignUpSignInPolicyId": "B2C_1_SiUpIn",
"ResetPasswordPolicyId": "B2C_1_PwdReset",
"EditProfilePolicyId": "B2C_1_ProfileEdit",
}
然后是您的路线:
public abstract BaseRouteBuilder extends RouteBuilder {
@Override
public void configure() {
onException(Throwable.class).log("Excpetion caught");
}
}
如前所述,从子类中调用@AllArgsConstructor
public class MyCamelRoute extends BaseRouteBuilder {
/**
* {@inheritDoc}
*/
@Override
public void configure() throws Exception {
super.configure();
// Route Configuration here
}
很重要,否则将不会执行exception子句。