test(Demo,xxx)
我想在路由a
中注入Shape实现
答案 0 :(得分:1)
这是绕过骆驼的解决方案:
由于您自己实例化了Bean,而不是依靠spring来管理它,因此可以通过构造函数传递Shape实现。
在您的DemoRoute类中添加一个Shape字段:
public class DemoRoute {
private final Shape shape;
public DemoRoute(Shape shape) {
this.shape = shape;
}
// test method that uses shape
}
并在您的Route配置类中,配置如下:
@Component
public class CustomRoute extends RouteBuilder {
private final Square square;
private final Circle circle;
CustomRoute(Square square, Circle circle){
this.square = square;
this.circle = circle;
}
@Override
public void configure() throws Exception {
from("direct:myRoute1")
.bean(new DemoRoute(circle), "test(Demo,xxx)")
.end();
from("direct:myRoute2")
.bean(new DemoRoute(square), "test(Demo,xxx)")
.end();
}
}