from("direct:myRoute1")
.bean(new DemoRoute(), "test(Demo,xxx)")
.end();
from("direct:myRoute2")
.bean(new DemoRoute(), "test(Demo,xxx)")
.end();
public interface Shape
@Component
class Circle implements Shape{
}
@Component
class Square implements Shape{}
I want to inject the Shape implementation in route test(Demo,xxx)
Pros and Cons of setting Lot of headers in Camel Exchange
Here is a solution to bypass Camel :
Since you are instanciating the bean yourself and not relying on spring to manage it, you could pass the Shape implementation through a constructor.
Add a Shape field in your DemoRoute class:
public class DemoRoute {
private final Shape shape;
public DemoRoute(Shape shape) {
this.shape = shape;
}
// test method that uses shape
}
And in your Route config class, configure as follow :
@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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With