springcloud 6 spring cloud config

简介

集中式的、动态的配置管理设施,配置服务器为各个不同微服务应用的所有环境提供了一个中心化的外部配置。

功能

  1. 集中管理配置文件

  2. 不同环境不同配置,动态化的配置更新

  3. 服务向配置中心统一拉取配置

  4. 配置变动时,服务无需重启即可刷新

  5. 配置信息以rest接口的形式暴露

Config服务端配置

  1. yml配置
server:   
	port: 3344  
spring:   
	application:    
		name: cloud-config-center   
	cloud:    
		config:     
			server:      
				git:       
					uri: 填写你自己的github路径       
					search-paths:        
						- springcloud-config     
					label: master  
eureka:   
	client:    
		service-url:     
			defaultZone: http://localhost:7001/eureka  
  1. 主启动类加@EnableConfigServer

  2. 访问http://localhost:3344/master/config-dev.yml测试

配置读取规则:/{label}/{application}-{profile}.yml对应分支-服务名-环境

Config客户端配置

  1. bootstrap.yml—系统级别,优先级更高,默认不会被本地属性覆盖。
server:   
  port: 3355     
spring:   
  application:    
  	name: config-client   
  cloud:    
  	config:     
  		label: master     
  		name: config     
  		profile: dev     
  		uri: http://localhost:3344  
eureka:   
  client:    
  	service-url:     
  		defaultZone: http://eureka7001.com:7001/eureka  
  1. 业务类用@Value即可注入从中心取得的配置

  2. 测试:http://localhost:3355/configInfo

动态刷新 修改客户端

  1. pom引入actuator配置

  2. 修改yml

management:
endpoints:
  web:
    exposure:
      include: "*"
  1. controller类加@RefreshScope

  2. 发送post请求curl -X POST "http://localhost:3355/actuator/refresh"刷新

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值