天天看点

Spring Cloud Consul启动时相关服务不能注册到Consul注册中心

(网上说法不一)

如下亲测........(大部分是因为项目引用的Consul相关jar包与Consul注册中心不匹配)

本例使用的Consul是1.5.2版本

[[email protected] ~]# consul version

Consul v1.5.2

Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)

问题描述: 项目能正常启动,但相关服务不能注册到Consul注册中心

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
<!--<version>2.1.2.RELEASE</version>-->  --不能注册 
<!--<version>2.1.1.RELEASE</version>-->  --不能注册 
<!--<version> 2.1.3.RELEASE</version>-->  --不能注册  
<!--<version>2.1.0.RELEASE</version>-->--能注册   
<version>2.0.9.RELEASE</version>  --能注册 
<relativePath/>
</parent>
           

springcloud版本为:

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-dependencies</artifactId>
  <version>Finchley.RELEASE</version>
  <type>pom</type>
  <scope>import</scope>
</dependency>
           
spring-cloud-starter-consul-discovery.2.0.0.RELEASE               spring-cloud-starter-consul-config.2.0.0.RELEASE
           

能成功注册的服务的日志如下:

Spring Cloud Consul启动时相关服务不能注册到Consul注册中心