首页 > 解决方案 > Spring Cloud Config 刷新配置

问题描述

是否可以刷新调用 java 方法的配置而不是使用 REST api:

curl localhost:8080/actuator/refresh -d {} -H "Content-Type: application/json"

标签: spring-bootspring-cloud-config

解决方案


您可以从以下位置使用ResartEndpoint 类spring-cloud-context

@Autowired
private RestartEndpoint restartEndpoint;

...

Thread restartThread = new Thread(() -> restartEndpoint.restart());
restartThread.setDaemon(false);
restartThread.start();

这就是@alexbt 建议的方式。但请注意,spring cloud 文档还说您可以刷新单个 bean,只要它们是 RefreshScope。


推荐阅读