1. 添加pom
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
为什么一定要加actuator依赖呢?
有了actuator这个依赖,就可以使用/refresh 这个节点来刷新带有
@RefreshScope
注解服务的bean
2. 修改启动类
添加注解@RefreshScope
注解@RefreshScope
拓展:
3. 在贴一下server 和 client 的配置代码
算了 不贴了,和以前一样的。
server:
Spring Cloud Config Server
client:
SpringCloud Config Client
启动config server和 client 服务
-
先来访问/profile 看服务是否正常运行
-
修改git上的application-dev.yml配置
- 再次访问/profile
我们发现它并没有发生变化。这需要我们的一个触发操作
发送一个post
请求给/refresh
再来看看 client端 控制台打印:
意思是得到刷新指令后,重新从server获取 配置仓库的内容。
注意!@RefreshScope和 @Configuration在同一类上使用有冲突: