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

时间:2019-07-01 09:57:04

标签: spring spring-boot apache-camel spring-camel

我在应用程序中使用骆驼,我想创建一个SmartLifeCycle bean,它在CamelContext之前启动。

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

在我的计算机上运行良好,我的bean在SpringCamelContext bean之前启动。

但是,一旦我在服务器上进行部署,SpringCamelContext便会启动。

知道为什么吗?以及如何确保我的bean之前已启动?

谢谢

修改

看起来像SpringCamelContext是“ LifeCycle” Bean,而不是“ SmartLifeCycle” Bean。根据文档:

 <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.

但是我仍然不知道该如何解决(如何知道使用负值不会产生某种副作用?)为什么它在我的本地计算机上可以工作?

编辑2:

区别在于管理配置。 如果我使用其他端口作为管理端口,而这使用另一种配置:DifferentManagementContextConfiguration。

启动时,在Configuration上调用方法“ afterSingletonsInstantiated()”,并创建一个立即刷新的managementContext。

此上下文在主ApplicationContext刷新之前和LifeCycleProcessor启动之前刷新。

此刷新由于其中的ContextRefreshedEvent侦听器而正在初始化SpringCamelContext。

我还在寻找可以解决此问题的方法...

1 个答案:

答案 0 :(得分:0)

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