一、下载地址
官网
https://www.consul.io/downloads.html
或者我的网盘,服务到位吧
链接:https://pan.baidu.com/s/1G3J4-N1I8tkk9Bxcyj_Vpw
提取码:cid4
复制这段内容后打开百度网盘手机App,操作更方便哦
启动consul,在consul目录下面cmd
consul agent -dev
http://localhost:8500/ui/dc1/services 查看这个界面我还是蛮喜欢的,哈哈哈
然后呢,跟之前一样,在父工程中新建module,导入pom,创建yml,创建启动类四部曲
pom来也
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-consul-discovery -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
yml如下
server:
port: 8006
spring:
application:
name: consul-provider-payment
cloud:
consul:
host: localhost
port: 8500
discovery:
service-name: ${spring.application.name}
启动测试就好了,查看是否注册进consul