Spring boot config registry [Spring boot config 配置中心]

本文介绍了如何设置和使用Spring Boot Config Server作为配置中心,详细阐述了添加依赖、启用Config Server、配置文件的获取方式,以及Config Client的配置方法,包括添加依赖、使用@ConfigurationProperties和@RefreshScope注解,以及通过bootstrap.yml加载远程配置。同时,文章还讨论了在Spring Boot 2.0及以后版本中如何开启主动更新远程配置。
摘要由CSDN通过智能技术生成

Spring boot config registry [Spring boot config 配置中心]

Spring boot config Server

  1. 添加依赖
<!-- config server -->
<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-config-server</artifactId>
</dependency>
  1. 启用
    启动类添加 @EnableConfigServer 注解
  2. 配置文件
spring:
  cloud:
    config:
      server:
        git:
          # git/svn/file system. example: https://gitee.com/[your git repsitory].git 
          uri: [your git repository]
          # 配置文件所在路径
          search-paths: profiles
          # git 用户名 & 密码, 如public项目, 可省略
          username: 
          password: 
        # 如不加该前缀,spring boot start config 会拦截根url下静态资源
        prefix: /config
      # 配置文件所在分支
      label: master
      # 仅作为配置中心使用,不会更新远程配置
      enabled: false
  1. 使用方式
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值