我有一个遗留代码,其中在服务启动后,在consul中注册了spring boot应用程序。该应用程序自动装配ConsulLifecycle spring bean,通过它使用内置方法ConsulLifecycle.start()和ConsulLifecycle.stop()在consul中注册/注销服务。
现在,我们已经将spring升级到5.1.5,将spring-cloud-starter-consul-discovery升级到2.1.1,并将spring-cloud-dependencies升级到Greenwich。RELEASE,其中删除了ConsulLifecycle bean。因此,为了实现相同的行为,我尝试自动装配ConsulAutoServiceRegistration弹簧bean,并使用其start和stop方法在consul中注册和注销该服务。
现在的问题是,当我尝试启动Spring Boot应用程序时,我在应用程序启动时遇到一些错误(该帖子的最后一部分中提到的错误)。
注意:我在其中定义了此属性的application.properties文件中
spring.cloud.consul.host=127.0.0.1
spring.cloud.consul.port=8500
##Embedded Tomcat
server.port = 8091
server.address = 0.0.0.0
我在应用程序启动时遇到的错误,即在向领事注册服务时遇到的错误
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)
答案 0 :(得分:0)
您的application.properties
也应具有以下属性:
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}