- SpringBoot 2.3.5.RELEASE
- SpringCloud Hoxton.SR6
1 - 下载consul
启动consul(windows) 命令 consul agent -dev
访问页面:http://localhost:8500
2 - 父项目maven聚合
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
</parent>
<properties>
<spring.cloud-version>Hoxton.SR6</spring.cloud-version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
2 - 开发consul client 客户端
pom
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<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>
</dependencies>
consul 会自动向client端发送心跳检查,所以client 必须引入健康检查依赖
application.yml
server:
port: 7001
spring:
application:
name: CONSULAPPLICATION
cloud:
consul:
port: 8500
host: localhost
入口类
@SpringBootApplication
@EnableDiscoveryClient
public class ConsulApplication7001 {
public static void main(String[] args) {
SpringApplication.run(ConsulApplication7001.class, args);
}
}