spring Cloud-config-分布式环境下自动发现配置服务

 

Config-server是其中的Service Provider,

Config-client是Service Consumer,

它们都注册到服务中心Eureka Server。

 1. 将config-server注册到服务中心

参考服务注册。访问http://localhost:8761, 可以看到我们的config-server已经注册。

2.修改配置文件

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
spring:
  application:
    name: config-client
  cloud:
    config:
      label: master
      profile: dev
#      uri: http://localhost:8888/
      discovery:
         enabled: true
         serviceId: config-server
management:
  security:
    enabled: false
server:
  port: 8881

注释掉了硬编码的config-server的URL配置, 取而代之的是服务注册中心的地址http://localhost:8761/eureka/以及配置服务的名字“config-server”, 同时打开自动发现机制discovery.enable = true.

我们在运行一下hello world应用, 可以发现, GIT里面的内容依然可以访问。此时我们的hello world应用已经完全不知道配置服务的地址,也不知道配置的内容, 所有这些都通过服务注册中心自动发现。

 

转载自:http://www.cnblogs.com/chry/p/7262088.html

posted @ 2018-04-02 22:24  林被熊烟岛  阅读(177)  评论(0编辑  收藏  举报