使用Spring Cloud Config Server,
启动Service时会从配置中心取配置文件,并注入到应用中,如果在Service运行过程中想更新配置,需要使用Spring Cloud Bus配合实现实时更新。
需要借助RabbitMQ等消息中间件来实现服务间的通讯
目标:使ConfigServer暴露bus-refresh接口,通过bus通知服务更新配置
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
management.endpoints.web.exposure.include=bus-refresh
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
@RefreshScope @Controller public class LblController {
1. 修改git仓库上的配置文件
Service配置没有更新
2. 调用http://localhost:8081/actuator/bus-refresh(POST)
Service配置更新
本篇文章就到这里了,希望能够给你带来帮助,也希望您能够多多关注的更多内容!