1.分布式配置中心 spring-cloud-config

pring Cloud 版本:2.1.0.RELEASE

一、server端

1.maven依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
    <version>2.1.0.RELEASE</version>
</dependency> 

2.配置文件

注:application.yml

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8080/eureka/
server:
  port: 8888
spring:
  application:
    name: module-config-server     #注册的服务名
  cloud:
    config:
      server:
        git:
          uri: https://github.com/XXX  #git地址
          search-paths: /config     #git下的路径
          username:   #git用户名
          password:   #git密码

3.源码解析

 

二、client端

1.maven依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
    <version>2.1.0.RELEASE</version>
</dependency>

 2.配置文件

扫描二维码关注公众号,回复: 5141676 查看本文章

注:bootstrap.yml,此时必须使用bootstrap.yml,优先级大于application.yml,可以在启动的时候去server端fetch配置文件的信息

server:
  port: 8081
eureka:
  instance:
    hostname: localhost
    appname: order
  client:
    service-url:
      defaultZone: http://localhost:8080/eureka/
spring:
  application:
    name: order
  cloud:
    config:
      discovery:
        enabled: true
        service-id: module-config-server
    #  enabled: true 可以省略
      label: master
      profile: dev
    #  uri: http://localhost:8888/ 默认就是这个地址,可以省略,有service-id时,优先使用service-id
 

猜你喜欢

转载自www.cnblogs.com/Hleaves/p/10348126.html
今日推荐