springboot2.X整合consul

1.添加依赖

        
            org.springframework.boot
            spring-boot-starter-actuator
        
        
            org.springframework.cloud
            spring-cloud-starter-consul-discovery
        

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

你可能感兴趣的:(springboot2.X整合consul)