打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
springcloud(第二篇)springcloud 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@RefreshScopepublic 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);    }}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
【安全鉴权】Spring Boot Actuator如何进行安全鉴权?还得是这样。
Spring Cloud 中使用zookeeper作为服务注册中心与配置中心
SpringCloud第四篇:熔断器Hystrix
33、springboot整合springcloud
spring-boot(九)websocket配置
跨域请求设置
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服