Consul服务发现和配置管理

1.pom引入依赖

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

2.修改yml配置文件

spring:
  application:
    name: cloud-order-service
  cloud:
    consul:
      host: localhost
      port: 8500
      discovery:
        service-name: ${spring.application.name}

3.启动类加 @EnableDiscoveryClient 注解

@SpringBootApplication
@EnableDiscoveryClient
public class OrderConsulMain80 {
    public static void main(String[] args) {
        SpringApplication.run(OrderConsulMain80.class, args);
    }
}

 

上一篇:docker-compose搭建consul集群


下一篇:Java中高级岗面试为何越来越难?原理+实战+视频+源码