1.版本說明
springboot 2.2.5.RELEASE
springcloud Hoxton.SR6
2.依賴
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<!--引入consul client依賴--> < dependency > < groupId >org.springframework.cloud</ groupId > < artifactId >spring-cloud-starter-consul-discovery</ artifactId > </ dependency > <!-- 注意:必須引入健康檢查依賴,如果沒有引入這個依賴,及時服務可用 但是在consul服務注冊中獲取不到服務狀態,consul注冊中心始終認為不可用 --> < dependency > < groupId >org.springframework.boot</ groupId > < artifactId >spring-boot-starter-actuator</ artifactId > </ dependency > |
3.配置文件
1
2
3
4
5
6
7
8
|
server.port=8083 spring.application.name=consulclient spring.cloud.consul.host=localhost spring.cloud.consul.port=8500 spring.cloud.consul.discovery.register-health-check= true spring.cloud.consul.discovery.service-name=${spring.application.name} |
4.啟動注解
1
2
3
4
5
6
7
8
9
|
@SpringBootApplication @EnableDiscoveryClient public class ConsulclientApplication { public static void main(String[] args) { SpringApplication.run(ConsulclientApplication. class , args); } } |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://www.cnblogs.com/taohaijun/p/13457088.html