2016-08-11 96 views
0

我目前在Websphere Liberty中運行Spring Boot應用程序,並使用Consul進行服務發現。爲了向Consul註冊服務,我創建了一個Liberty功能,用於連接應用程序生命週期事件並執行註冊/註銷。這很好,但通過這樣做,我將自己與Liberty聯繫在一起。 Spring-Cloud-Consul看起來好像可以解決這個問題,但我無法通過Liberty(它連接到Consul)註冊服務 - 只能使用嵌入式Tomcat服務器。查看Spring-Cloud-Consul代碼後,問題是EmbeddedServletContainerInitializedEvent未被觸發,因此沒有設置端口。Spring Cloud with Liberty

我的問題是,Spring Cloud Consul是否只能使用嵌入式servlet容器?

回答

0

我的解決辦法是,將彈簧雲領事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(); 
} 

現在我的服務註冊和註銷預期。