# spring-cloud-config **Repository Path**: honghh/spring-cloud-config ## Basic Information - **Project Name**: spring-cloud-config - **Description**: 动态刷新分布式配置中心属性配置(config) - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2018-04-18 - **Last Updated**: 2022-06-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # spring-cloud-config chapter2消息总线 ConfigClient配置自动刷新 ### Spring Cloud Bus: Spring Cloud Bus提供了批量刷新配置的机制,它使用轻量级的消息代理(例如RabbitMQ、Kafka等)连接分布式系统的节点,这样就可以通过Spring Cloud Bus广播配置的变化或者其他的管理指令。使用Spring Cloud Bus后的架构如图所示。 ![输入图片说明](https://gitee.com/uploads/images/2018/0420/132114_25d29e0f_1071933.png "屏幕截图.png") ### 准备工作: 需要安装rabbitMQ,安装rabbitMQ的详情请参考:https://blog.csdn.net/qq_35098526/article/details/80009424 这篇文章主要讲Windows下的安装过程。 ### 环境搭建 ![输入图片说明](https://gitee.com/uploads/images/2018/0420/132136_d9a38a11_1071933.png "屏幕截图.png") 创建三个模块: eureka-server eureka服务注册中心 config-server 配置中心服务端 config-client 配置中心客户端 ### 启动项目 依次启动eureka-server、confg-cserver,启动两个config-client,端口为:8881 1.访问http://localhost:8881/hi 浏览器显示: ![输入图片说明](https://gitee.com/uploads/images/2018/0420/132201_bfab5e00_1071933.png "屏幕截图.png") 2.这时我们去代码仓库将config-client-dev.properties 下的foo的值改为“foo version 4”,即改变配置文件foo的值。如果是传统的做法,需要重启服务,才能达到配置文件的更新。此时,我们只需要发送post请求:http://localhost:8881/bus/refresh,你会发现config-client会重新读取配置文件。可以看到控制台打印日志如图。注意有坑 ① ![输入图片说明](https://gitee.com/uploads/images/2018/0420/132226_52ac1c3b_1071933.png "屏幕截图.png") 3. 再次请求 http://localhost:8881/hi ![输入图片说明](https://gitee.com/uploads/images/2018/0420/132247_b2171af7_1071933.png "屏幕截图.png") 到这里操作就已经完成。接下来我们讲一下遇到的问题. ### 注意有坑 ① 上面提到请求 http://localhost:8881/bus/refresh但是你在运行的时候遇到报404的错误 图5.1 ![输入图片说明](https://gitee.com/uploads/images/2018/0420/132302_78b8737a_1071933.png "屏幕截图.png") 图5.2 ![输入图片说明](https://gitee.com/uploads/images/2018/0420/132311_147bc2bd_1071933.png "屏幕截图.png") 首先,你要确认是 post请求,如图5.1是get请求,是会报404的错误的 但是图5.2中用的是post请求为什么还会报错 这里就是我所说的坑 看项目中的pom文件 我用的是spring boot 2.0.1.RELEASE版本,查资料看到一篇文章 https://ask.csdn.net/questions/684123 所以这就是上面为什么这样改的原因,执行刷新的的请求为: http://localhost:8881/actuator/bus-refresh ### 下载地址: 代码我已同步到码云git :https://gitee.com/honghh/spring-cloud-config