There are a few possibilities when using spring beans in your camel routes. But 
I was wondering what the common best practice is.

1) Use the class in the .bean method:
from("direct://start")
.bean(MyService.class, "process")
.end();

Normally Camel will then create a new instance of MyService class.
But from what I've tested this won't happen if you do annotate the service with 
@Service (or @Component). 
So no new Myservice instance is created and the Spring managed bean is used.


2) The other possibility is to use autowiring

@Autowired
Private MyService myService;
...
from("direct://start")
.bean(myservice, "process")
.end();


At the moment I'm using #2.
Because it's easier to see that it is in fact a spring managed bean. And not a 
newly created object.

Any thoughts?

Regards,
Diether


Reply via email to