1.添加依賴(lài)
<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.在主入口程序類(lèi)上增加 @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
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者