【问题标题】:Spring Cloud with Liberty带有 Liberty 的 Spring Cloud
【发布时间】:2016-12-18 08:17:33
【问题描述】:

我目前在 Websphere Liberty 中运行 Spring Boot 应用程序,并使用 Consul 进行服务发现。为了向 Consul 注册服务,我创建了一个 Liberty 功能,该功能与应用程序生命周期事件挂钩并执行注册/取消注册。这很好用,但这样做我将自己与 Liberty 耦合。 Spring-Cloud-Consul 看起来可以解决这个问题,但我无法让它向 Liberty 注册服务(它确实连接到 Consul)——只能使用嵌入式 Tomcat 服务器。查看 Spring-Cloud-Consul 代码后,问题是没有触发 EmbeddedServletContainerInitializedEvent,因此没有设置端口。

我的问题是,Spring Cloud Consul 是否仅适用于嵌入式 servlet 容器?

【问题讨论】:

    标签: spring-boot spring-cloud websphere-liberty consul


    【解决方案1】:

    这是一个已知问题。随意提交 PR。 https://github.com/spring-cloud/spring-cloud-consul/issues/173

    【讨论】:

    • 啊,谢谢您的回复。很高兴知道我在正确的轨道上。
    【解决方案2】:

    我的解决方案是将 spring-cloud-consul 的 ConsulLifecycle 类引入本地并添加一个 ApplicationReadyEvent,如下所示:

    @Autowired(required = false)
    private ServerProperties serverProperties;
    
    @EventListener
    public void onApplicationReady(ApplicationReadyEvent event) {
        this.setConfiguredPort(serverProperties.getPort());
        log.info("Application ready on port " + serverProperties.getPort());
        this.start();
    }
    

    现在我的服务按预期注册和注销。

    【讨论】:

      猜你喜欢
      • 2017-10-25
      • 2020-07-31
      • 1970-01-01
      • 2021-04-02
      • 1970-01-01
      • 2018-05-11
      • 2017-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多