I'm using camel in my application and I want to create a SmartLifeCycle bean which starts before the CamelContext.
In order to do that, I implemented a custom SmartLifeCycle bean with a phase of : Integer.MAX_VALUE - 101. SpringCamelContext has a phase of : Ordered.LOWEST_PRECEDENCE
On my computer its working great, my bean is started before the SpringCamelContext bean.
But once I deploy on my servers, the SpringCamelContext is started before.
Any idea why ? And how can I make sure my bean is started before ?
Thanks
Edit
Seems like SpringCamelContext is a "LifeCycle" bean and not a "SmartLifeCycle" bean. According to the documentation :
<p>Any {@code Lifecycle} components within the context that do not also
implement {@code SmartLifecycle} will be treated as if they have a phase
value of 0. That way a {@code SmartLifecycle} implementation may start
before those {@code Lifecycle} components if it has a negative phase value,
or it may start after those components if it has a positive phase value.
But I still don't know how to fix this (how can I know if using a negative value would not create some sort of side effects ?) And why is it working on my local computer ?
Edit 2:
The difference was in the management configuration. If I'm using a different port for the management port, and this use another configuration : DifferentManagementContextConfiguration.
On startup, the method "afterSingletonsInstantiated()" is called on the Configuration and it creates a managementContext which is refreshed immediatly.
This context is refreshed before the main ApplicationContext refresh and before the LifeCycleProcessor is started.
This refresh is initializing SpringCamelContext due to the ContextRefreshedEvent listener in it.
I'm still looking for something to fix this ...
This is a known bug which has been fixed in 2.24.1 camel version