consul部署

2021-01-14  本文已影响0人  o_O小薯条

Spring Cloud服务治理

Consul

安装执行Consul

./consul agent -dev

client客户端配置

1. client客户端坐标

<dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-consul-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
</dependencies>

2. client客户端yml配置

server:
  port: 8000
  
spring:
  cloud:
    consul:
      host: localhost #consul服务端的 ip
      port: 8500 # consul服务端的端口 默认8500
      discovery:
        service-name: ${spring.application.name} #当前应用注册到consul的名称
        prefer-ip-address: true #注册ip
  application:
    name: consul-provider #应用名称

3. client客户端启动应用

上一篇 下一篇

猜你喜欢

热点阅读