配置中心 Spring Cloud config

配置管理工具包,让你可以把配置放到远程服务器,集中化管理集群配置,目前支持本地存储、Git以及Subversion。

1.服务端  

   创建spring boot 项目 

   主要依赖 

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

知识兔

  新版本好像不包括 web 需加入web依赖 

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

知识兔

在启动类上声明 


配置文件 application.yml

知识兔

spring:
  application:
    name: config
  cloud:
    config:
      server:
        git:
          uri: #git 地址
          search-paths: #git的路径
          username: #账号
          password: #密码
          basedir: #本地存放路径
      label: master #分支

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
server:
  port: 8888

知识兔

 引入依赖 

知识兔

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

知识兔

配置文件 要用bootstrap.yml  (用来程序引导时执行,应用于更加早期配置信息读取)

??于有eureka的配置 通过id寻找配置中心

知识兔

#spring:
# cloud:
# config:
# discovery:
# service-id: config
# enabled: true
# profile: dev
# name: product
# label: master

通过url 寻找配置中心
spring:
cloud:
config:
label: master #分支
profile: dev #配置描述
uri: http://localhost:8888
name: product #名称 设置了application.name 可省略
计算机