title: Registering spring boot application with consul after service is bootup
body: <p>I have a legacy code where a spring boot application is registered with consul after the service boot up. The application autowires ConsulLifecycle spring bean through which it register/un-register the service with consul using its inbuild method ConsulLifecycle.start() and ConsulLifecycle.stop().</p>
  
  <p>Now we have upgraded spring to 5.1.5, spring-cloud-starter-consul-discovery to 2.1.1 and spring-cloud-dependencies to Greenwich.RELEASE in which  ConsulLifecycle bean is removed. So for achieving the same behaviour, I am trying to autowire ConsulAutoServiceRegistration spring bean and using its start and stop method to register and unregister the service with consul.</p>
  
  <p>The issue is now when I am trying to start the spring boot application I am getting some error on application boot up(error mentioned in the last section of the post). </p>
  
  <p>Note: I have application.properties file where I have defined this property</p>
  
  <pre><code>spring.cloud.consul.host=127.0.0.1
  spring.cloud.consul.port=8500     
  ##Embedded Tomcat 
  server.port = 8091
  server.address = 0.0.0.0
  </code></pre>
  
  <p>The Error I am facing on application bootup i.e. while registering service with the consul</p>
  
  <pre><code>2:25 - Unknown error occured.
  java.lang.IllegalArgumentException: service.port has not been set
      at org.springframework.util.Assert.notNull(Assert.java:198)
      at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration.getRegistration(ConsulAutoServiceRegistration.java:56)
      at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration.getRegistration(ConsulAutoServiceRegistration.java:32)
      at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.start(AbstractAutoServiceRegistration.java:117)
      at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration.start(ConsulAutoServiceRegistration.java:68)
  at com.bmc.agent.data.refresh.manager.core.ConsulLeaderElectionHelper.checkAndGetLocalService(ConsulLeaderElectionHelper.java:201)
  at com.bmc.agent.data.refresh.manager.core.ConsulLeaderElectionHelper.run(ConsulLeaderElectionHelper.java:152)
  </code></pre>