1
votes

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().

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.

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).

Note: I have application.properties file where I have defined this property

spring.cloud.consul.host=127.0.0.1
spring.cloud.consul.port=8500     
##Embedded Tomcat 
server.port = 8091
server.address = 0.0.0.0

The Error I am facing on application bootup i.e. while registering service with the consul

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)
1
Why are you even doing manual registration? The inclusion should be enough to have it automatically registered. Also the fact that it is deprecated doesn't mean you cannot still use it.M. Deinum
Let me edit my comments, it is not deprecated but removed. Regarding manual registration: It is an older implementation and I do not want to change itProgrammer
The only change would be delete it and add an annotation to do the auto-registration (which would call the same code afaik).M. Deinum

1 Answers

0
votes

Your application.properties should have the following properties as well:

spring.cloud.consul.discovery.healthCheckPath=${spring.application.name}/ManagementEndPoints/health
spring.cloud.consul.discovery.healthCheckInterval=5s
spring.cloud.consul.discovery.instance-id=${spring.application.name}
spring.cloud.consul.discovery.scheme=http or https
spring.cloud.consul.discovery.hostname=${spring.application.name}
spring.cloud.consul.discovery.port=${server.port}