简体   繁体   English

如何使SmartLifeCycle bean在SpringCamelContext之前启动?

[英]How to make SmartLifeCycle bean start before SpringCamelContext?

I'm using camel in my application and I want to create a SmartLifeCycle bean which starts before the CamelContext. 我在应用程序中使用骆驼,并且想要创建一个在CamelContext之前启动的SmartLifeCycle bean。

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 为此,我实现了一个自定义SmartLifeCycle bean,其阶段为:Integer.MAX_VALUE-101。SpringCamelContext的阶段为:Ordered.LOWEST_PRECEDENCE

On my computer its working great, my bean is started before the SpringCamelContext bean. 在我的计算机上,它的运行正常,我的bean在SpringCamelContext bean之前启动。

But once I deploy on my servers, the SpringCamelContext is started before. 但是,一旦我在服务器上部署了SpringCamelContext,就可以启动它了。

Any idea why ? 知道为什么吗? And how can I make sure my bean is started before ? 以及如何确保我的bean之前已启动?

Thanks 谢谢

Edit 编辑

Seems like SpringCamelContext is a "LifeCycle" bean and not a "SmartLifeCycle" bean. 似乎SpringCamelContext是“ LifeCycle” Bean,而不是“ 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: 编辑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. 如果我使用其他端口作为管理端口,则使用另一种配置:DifferentManagementContextConfiguration。

On startup, the method "afterSingletonsInstantiated()" is called on the Configuration and it creates a managementContext which is refreshed immediatly. 在启动时,在配置上调用方法“ afterSingletonsInstantiated()”,并创建一个立即刷新的managementContext。

This context is refreshed before the main ApplicationContext refresh and before the LifeCycleProcessor is started. 在刷新主ApplicationContext之前和LifeCycleProcessor启动之前,将刷新此上下文。

This refresh is initializing SpringCamelContext due to the ContextRefreshedEvent listener in it. 由于其中有ContextRefreshedEvent侦听器,因此此刷新正在初始化SpringCamelContext。

I'm still looking for something to fix this ... 我仍在寻找解决此问题的方法...

这是一个已知的错误,已在2.24.1骆驼版本中修复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM