Java camel Advice with RouteBuilder不推荐

Java camel Advice with RouteBuilder不推荐,java,apache-camel,Java,Apache Camel,我正在使用camel 2.15.1,并尝试使用adviceWith(),但我不断收到反对警告。以下是相关片段: routeDefinition.adviceWith(camelContext, new AdviceWithRouteBuilder(){ @Override public void configure() throws Exception { interceptSendToEndpoint("direct:doSomethin

我正在使用camel 2.15.1,并尝试使用adviceWith(),但我不断收到反对警告。以下是相关片段:

routeDefinition.adviceWith(camelContext, new AdviceWithRouteBuilder(){
        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("direct:doSomething")
                .skipSendToOriginalEndpoint()
        }
    });
我知道我可以通过将camelContext强制转换为ModelCamelContext来避免弃用警告,但这样的转换有点异味。铸造是正确的处理方式吗


在未来的版本中,这些弃用已被删除,因为我们真的只希望人们能够从
CamelContext
访问他们所需要的所有内容

但是它有一个调整方法,因此您可以在不进行类型转换的情况下调整类型

ModelCamelContext mcc = context.adapt(ModelCamelContext.class);

这解决了我的单元测试的问题:

public void testMe() throws Exception{
    CamelContext context = this.context();

    // Get the route that we're after by ID.
    RouteDefinition route = context.getRouteDefinition("<routeID>");

    //override the default send endpoint.
    route.adviceWith(context.adapt(ModelCamelContext.class), new RouteBuilder() {
        public void configure() throws Exception {
            interceptSendToEndpoint("mock:overrideme")
                .skipSendToOriginalEndpoint()
                .to("mock:inbound");
        }
    });
}
public void testMe()引发异常{
CamelContext=this.context();
//通过ID获取我们要追踪的路线。
RouteDefinition route=context.getRouteDefinition(“”);
//覆盖默认的发送端点。
route.adviceWith(context.adapt(ModelCamelContext.class),newRouteBuilder(){
public void configure()引发异常{
interceptSendToEndpoint(“模拟:覆盖”)
.skipSendToOriginalEndpoint()
。至(“模拟:入境”);
}
});
}

因此,我不确定这将如何取代使用adviceWith,您如何使用此方法调整路线中的端点,而不是通过adviceWith进行调整?Camel 2.13.0中不存在
adapt
方法,那么我应该依赖不推荐的方法吗?您可以键入cast the CamelContext