频道栏目
首页 > 资讯 > 其他综合 > 正文

SpringCloud之Config Client 配置过程讲解

18-07-20        来源:[db:作者]  
收藏   我要投稿

SpringCloud之Config Client 配置过程讲解

Spring Cloud Config Client 配置过程


1、pom.xml 添加依赖

    org.springframework.boot
    spring-boot-starter-parent
    2.0.3.RELEASE
     



    UTF-8
    UTF-8
    1.8
    Finchley.RELEASE



    
    
        org.springframework.cloud
        spring-cloud-starter-config
    
    
    
        org.springframework.boot
        spring-boot-starter-actuator
    
    
        org.springframework.boot
        spring-boot-starter-test
        test
    
    
    
        org.springframework.boot
        spring-boot-starter-web
    



    
        
            org.springframework.cloud
            spring-cloud-dependencies
            ${spring-cloud.version}
            pom
            import
        
    



    
        
            org.springframework.boot
            spring-boot-maven-plugin
        
    
2、添加配置信息

application.yml

server:
  port: 8080 # 指定监听端口

# 加载所有的端点。默认只加载了 info / health
management:
  endpoints:
    web:
      exposure:
        include: "*"

bootstrap.yml

spring:
  application:
    name : configClient01
  cloud:
    config:
      profile: test
      label: master
      uri: http://localhost:8090

配置解释:

spring.cloud.config.*:默认情况下,Config Server 会提供来自/{name}/{profile}/{label}的属性来源,其中 Config Client 中的默认绑定是:

"name" = ${spring.application.name} "profile" = ${spring.profiles.active} (actually Environment.getActiveProfiles()) "label" = "master"

但是,所有这些都可以通过设置spring.cloud.config.*(其中*为“name”,“profile”或“label”)来覆盖。(这里我们使用的是这种方式)

label 对于回滚到以前版本的配置非常有用;使用默认的 Config Server 实现时,label 可以是 git label,branch name 或者 commit id。label 也可以作为逗号分隔的列表提供,在这种情况下,列表中的项目将逐个尝试,直到一个成功。例如,当在一个 feature 分支上开发时,可能希望将 label 与分支对应,但将其设置为可选的(例如,spring.cloud.config.label = myfeature,develop)。

spring.cloud.config.uri:Config Server 的地址; spring.application.name:配置应用名称(有注册中心时用于对应用进行标识),这里暂时没有什么用处(也被上边覆盖掉了);

3、对 Config Server 端配置进行修改

只需要修改 search-paths,至于为什么这样做,请看这里:《Spring Cloud 探索 | 分布式配置中心(Config Server)》

spring:
  cloud:
    config:
      server:
        git:
          search-paths : '{application}'
相关TAG标签
上一篇:MySql利用if..then..elseif..then..else..endif实现优、良、差等级的代码教程
下一篇:MySQL的数据库操作(DDL)和数据类型讲解
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站