Hi Giannis, I don't think you need that while loop, the CamelContext::stop method should block until CamelContext is stopped, and is there a reason you implemented SmartLifecycle instaed of Lifeycle? I ask because we had that discussion on the PR and came to conclusion that SmartLifecycle in our use-case does not provide any advantage over Lifecycle.
In order to test the code as it is in the PR, you would need to get the source code from the GitHub repository, and build that branch's version of Camel, something like: $ git clone https://github.com/apache/camel.git $ git fetch origin pull/1685/head:pr1685 $ git checkout pr1685 $ mvn -Pfastinstall install The last command should build (after ~20 minutes or so) the jar files and place them in your local Maven repository so that you can reference those with the version 2.20.0-SNAPSHOT. zoran On Fri, May 12, 2017 at 11:34 AM, giannis_k <[email protected]> wrote: > Hello Zoran, > > thank you for the input it was really helpful. I tried it and although I can > see that now the camel context definately shuts down first, the other beans > are still shut down before camel context is closed probably because the > shutdown of routes happen asychronously. What I ended up doing to overcome > this issue is to place a loop inside my 'SmartLifecycle' bean to wait for > the camel context to close. Here is my workaround: > > public class SpringBootCamelFix implements SmartLifecycle { > > private static final Logger log = > LoggerFactory.getLogger(SpringBootCamelFix.class); > > @Autowired > DefaultCamelContext context; > > > @Override > public void start() {} > > @Override > public void stop() { > > if (!isRunning()) { > log.info("Camel context already stopped"); > return; > } > > log.info("Stopping camel context. Will wait until it is > actually > stopped"); > > try { > context.stop(); > } catch (Exception e) { > e.printStackTrace(); > } > > while(context.isStarted()); > } > > @Override > public boolean isRunning() { > return context.isStarted(); > } > > @Override > public int getPhase() { > return Integer.MAX_VALUE; > } > > @Override > public boolean isAutoStartup() { > return false; > } > > @Override > public void stop(Runnable callback) { > stop(); > callback.run(); > } > } > > > I would also like to test your changes however where can I get a jar with > your changes in order to test it locally? > > Thanks, > Giannis > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Camel-spring-boot-destroys-beans-with-wrong-order-tp5799304p5799359.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Zoran Regvart
