官网地址:https://github.com/consul/consul
找不到包去maven仓库:https://mvnrepository.com/
consul官网下载地址:Release 1.5.0 · consul/consul · GitHub
下载得到exe文件:cmd进入当前exe目录,执行:
查看版本:consul --version
启动服务:consul agent -dev
- 导入依赖
- yml配置
- 启动类注解
1、导入依赖(版本需要与consul.exe的version一致,否则会报错)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
<version>1.3.6.RELEASE</version>
</dependency>
<!--服务数据监控包-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2、yml配置
spring: application: name: consul-comsumer cloud: consul: host: localhost port: 8500 discovery: service-name: consul-comusmer
3、启动类注解
@EnableDiscoveryClient