加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

spring cloud学习教程之config修改配置详解

发布时间:2020-12-14 19:52:17 所属栏目:Java 来源:网络整理
导读:之前我们讲过了spring cloud之config配置的相关内容,那么在Git端修改配置后如何让客户端生效?下面来一起看看详细的介绍吧。 访问接口修改 refresh post方式执行http://localhost/refresh 会刷新env中的配置 restart 如果配置信息已经注入到bean中,由于bea

之前我们讲过了spring cloud之config配置的相关内容,那么在Git端修改配置后如何让客户端生效?下面来一起看看详细的介绍吧。

访问接口修改

refresh

post方式执行http://localhost/refresh 会刷新env中的配置

restart

如果配置信息已经注入到bean中,由于bean是单例的,不会去加载修改后的配置

需要通过post方式去执行http://localhost/restart,

需要通过application.properties中配置endpoints.restart.enabled=true启动指定的端口

弊端: 通过restart耗时比较长,因此就有了RefreshScope

RefreshScope

package com.lkl.springcloud.config.client;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by liaokailin on 16/4/28.
 */
@EnableAutoConfiguration
@ComponentScan
@RestController
@RefreshScope
public class Application {

 @Value("${name:World!}") String name ;

 @RequestMapping("/")
 public String home(){
 return "Hello " + name;
 }


 public static void main(String[] args) {
 SpringApplication.run(Application.class,args);
 }
}

在执行refresh时会刷新bean中变量值。

ok ~ it's work ! more about is here (也可以通过本地下载)

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对编程小技巧的支持。

您可能感兴趣的文章:

  • spring-cloud入门之spring-cloud-config(配置中心)
  • 详解spring cloud config实现datasource的热部署
  • spring cloud学习入门之config配置教程
  • spring cloud config分布式配置中心的高可用问题

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读