九、Spring Cloud Config Server详解(八):@RefreshScope详解-手动刷新Config配置

本文详细介绍了如何在Spring Cloud Config Server项目中实现手动刷新配置。通过创建新的客户端项目futurecloud-config-client-eureka-refresh,引入依赖并使用@RefreshScope注解,当云端配置文件变更时,通过发送POST请求到/actuator/refresh接口来刷新配置,从而使得客户端应用获取到最新的配置信息。
摘要由CSDN通过智能技术生成

9.9.手动刷新Config配置


当云端(我们使用gitee)我们的配置文件内容发生变化时,我们项目的客户端却没有发生变化,这怎么办呢?

1、创建一个项目:从futurecloud-config-client-eureka复制一份,得到futurecloud-config-client-eureka-refresh项目
引入依赖:


 <!--引入安全认证依赖-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-security</artifactId>
    <version>2.0.0.RELEASE</version>
</dependency>

后面我们使用post请求时,需要登录eureka


2、修改controller 类,增加注解@RefreshScope //开启更新功能

package com.futurecloud.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值