配置yaml内容如下:
spring: cloud: consul: host: consul-dev.cmsp-dev.svc.cluster.local port: 8500 discovery: healthCheckInterval: 5s prefer-ip-address: true instanceId: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port} health-check-critical-timeout: 30s
pom.xml配置如下:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
consul的健康检查使用actuator提供的/actuator/health接口。