springboot2.X整合consul
2019-12-27 本文已影响0人
EnumaElish666
1.添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
2.在主入口程序类上增加 @EnableDiscoveryClient 注解
@SpringBootApplication
@EnableDiscoveryClient
public class SvcProducerApplication {
public static void main(String[] args) {
SpringApplication.run(SvcProducerApplication.class, args);
}
}
添加Consul配置
#Consul配置
#Consul配置
## 192.168.2.215
spring.cloud.consul.host=agent
spring.cloud.consul.port=8500
spring.cloud.consul.discovery.healthCheckUrl=http://localhost:${server.port}/health
spring.cloud.consul.discovery.instance-id=${spring.application.name}:${server.port}:${random.value}
spring.cloud.consul.discovery.hostname=agent
spring.cloud.consul.discovery.healthCheckInterval=5s
spring.cloud.consul.discovery.prefer-ip-address=true
spring.cloud.consul.discovery.enabled=true
spring.cloud.consul.discovery.heartbeat.enabled=true
spring.cloud.consul.discovery.register = true
spring.cloud.consul.discovery.register-health-check = true
spring.cloud.service-registry.auto-registration.enabled=true