【问题标题】:How to make SmartLifeCycle bean start before SpringCamelContext?如何让 SmartLifeCycle bean 在 SpringCamelContext 之前启动?
【发布时间】:2019-07-01 09:57:04
【问题描述】:

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

为了做到这一点,我实现了一个自定义 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。

我仍在寻找解决此问题的方法...

【问题讨论】:

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


    【解决方案1】:

    这是一个已知的bug,已经在2.24.1骆驼版中修复了

    【讨论】:

      猜你喜欢
      • 2014-05-29
      • 2020-03-15
      • 1970-01-01
      • 2017-01-03
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-20
      相关资源
      最近更新 更多