0

I am currently running a Spring Boot application inside of Websphere Liberty, and use Consul for Service Discovery. To register services with Consul, I created a Liberty feature that hooks in to the Application Lifecycle events and performs the registration /deregistration. This works great, but by doing so I am coupling myself to Liberty. Spring-Cloud-Consul looks like it might solve that issue, but I can't get it to register a service with Liberty (it does connect to Consul) - only with an Embedded Tomcat Server. After looking at the Spring-Cloud-Consul code, the issue is that a EmbeddedServletContainerInitializedEvent isn't being fired, so no port is being set.

My question is, does Spring Cloud Consul only work with embedded servlet containers?

J. Saiveau
  • 33
  • 3

2 Answers2

0

It is a known issue. Feel free to submit a PR. https://github.com/spring-cloud/spring-cloud-consul/issues/173

spencergibb
  • 24,471
  • 6
  • 69
  • 75
0

My solution was to bring spring-cloud-consul's ConsulLifecycle class local and add an ApplicationReadyEvent, like so :

@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();
}

Now my services register and deregister as expected.

J. Saiveau
  • 33
  • 3