我目前在Websphere Liberty中运行Spring Boot应用程序,并使用Consul for Service Discovery。为了向Consul注册服务,我创建了一个连接到Application Lifecycle事件并执行注册/deregistration的特权特性。这很好用,但这样做是将我自己与Liberty结合在一起。Spring-Cloud-Consul看起来可以解决这个问题,但我不能让它向Liberty注册服务(它确实连接到Consul) -只能使用嵌入式Tomcat Server。在查看了Spring-Cloud-Consul代码之后,问题是没有触发EmbeddedServletContainerInitializedEvent,所以没有设置端口。
我的问题是,Spring Cloud Consul只适用于嵌入式servlet容器吗?
发布于 2016-08-11 22:47:21
这是一个已知的问题。请随时提交公关。https://github.com/spring-cloud/spring-cloud-consul/issues/173
发布于 2016-08-25 04:15:38
我的解决方案是将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();
}现在,我的服务按照预期进行了注册和注销。
https://stackoverflow.com/questions/38898950
复制相似问题