Вот решение для обхода Camel:
Поскольку вы сами создаете экземпляр компонента и не полагаетесь на Spring для управления им, вы можете передать реализацию Shape через конструктор.
Добавитьполе Shape в вашем классе DemoRoute:
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();
}
}