One alternative is to observe for the CamelContextStartingEvent that’s fired 
before the corresponding Camel contexts get started, e.g.:

void initMyBeansBeforeContextStart(@Observes CamelContextStartingEvent event, 
MyBean bean) {
    bean.init();
}

Either method argument or class field injection will work. And that avoids 
having to override the start method on the context.

You can find more information in: 
http://camel.apache.org/cdi.html#CDI-CameleventstoCDIevents

Antonin

> On 10 Aug 2016, at 19:48, Rajith Muditha Attapattu <[email protected]> wrote:
> 
> I'm using CDI and want to make sure all my beans are loaded before the
> context and properly initialized.
> 
> I have them as attributes in my CamelContext class with @Inject.
> 
> However I override the start method in the context to make sure I call the
> various initi methods for those beans to make sure they are loaded and
> ready when the routes start.
> 
> @Override
> public void start() throws Exception{
>   myBean1.init();
>   myBean2.init().
>   super.start();
> }
> 
> Is this advisable ? is there a better way to do this ?
> 
> Regards,
> 
> Rajith Muditha Attapattu <http://rajith.2rlabs.com/>

Reply via email to