【问题标题】:unclear circular dependency with FeignClient and Spring bootFeignClient 和 Spring boot 的循环依赖不明确
【发布时间】:2019-07-25 09:56:09
【问题描述】:

在我添加以下类之前,我的 springboot 应用运行良好:

@Service
@RequiredArgsConstructor
public class AutoopsClientPostBootListener implements ApplicationListener<ContextRefreshedEvent>
{
    private final IAutoOpsGnsFlowInitiator gnsFlowInitator;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event)
    {
      gnsFlowInitator.startClient(event);
    }
}

在那之后出于某种奇怪的原因,我得到了一个循环依赖错误,源于 feign client 依赖于上面的 AutoopsClientPostBootListener

这是因为 IAutoOpsGnsFlowInitiator 依赖于依赖于 AutoopsClientPostBootListener 的 feign 客户端。但是FeignClient甚至没有任何成员..(feign自动生成)那它怎么可能依赖于Listener?!!

有什么问题??

感谢您的帮助

【问题讨论】:

    标签: spring-boot spring-cloud-feign


    【解决方案1】:

    所以问题出在 ApplicationListener(不知道为什么)。 使用@EventListener 解决了这个问题。

    @EventListener
        public void onApplicationEvent(ContextRefreshedEvent event)
        {
          gnsFlowInitator.startClient(event);
        }
    

    【讨论】:

      【解决方案2】:

      问题取决于您的上下文的阶段,一旦您的上下文被初始化或更改,就会调用刷新,因此您的事件将被触发,如果您需要在您的上下文完全初始化后执行您的 startClient 然后您@ 987654321@ 将由ContextStartedEvent 触发,只有在您的应用程序上下文完全初始化后才会调用它,因此 feign 已经加载。

      希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 2020-07-15
        • 2015-05-17
        • 2018-09-21
        • 1970-01-01
        • 2022-01-18
        • 2020-09-25
        • 2021-04-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多