spring cloud使用GitHub存配置取不到值的坑

本文详细介绍了如何使用Spring Cloud Config Server作为配置中心,包括客户端和服务端的配置方式,实时刷新配置的方法,以及如何通过Actuator进行配置更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

client端配置文件配置取信息的配置需要用bootstrap开头的文件名,加载顺序不同。

config-server中引入

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

config-client中引入

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>
client中配置:
spring.cloud.config.discovery.service-id=CONFIGSERVER --server的服务名
spring.cloud.config.uri=http://localhost:7001/  --server地址,不指定端口默认8888

实时刷新:

导入配置
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <version>2.1.6.RELEASE</version>
</dependency>
配置文件:management.endpoints.web.exposure.include=refresh,health

修改了GitHub的配置文件通过actuaor/refresh刷新,再次访问就是新的配置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值