之前我们讲过了的相关内容,那么在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 (也可以通过)
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对移动技术网的支持。
如对本文有疑问, 点击进行留言回复!!
Postgresql结合postgis使用java的JDBC连接
网友评论