2016-08-11 79 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(); 
} 

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