yog*_*ger 6 spring-boot spring-cloud-config
来自https://spring.io/guides/gs/centralized-configuration/:
您可以通过使用 Spring Cloud Config @RefreshScope 注解 MessageRestController 然后触发刷新事件来强制 Bean 刷新其配置(即从配置服务器中提取更新的值)。
我们如何触发这个刷新事件(对于用@ConfigurationProperties和注释的类@RefreshScope)?我们不想使用弹簧执行器/refresh端点。应用程序从配置服务器获取配置需要什么?
小智 9
RefreshEvent您可以使用自动装配来触发ApplicationEventPublisher. Spring Cloud 有一个该事件的监听器RefreshEventListener
@Autowired
private ApplicationEventPublisher eventPublisher;
public void fireRefreshEvent() {
eventPublisher.publishEvent(new RefreshEvent(this, "RefreshEvent", "Refreshing scope");
}
Run Code Online (Sandbox Code Playgroud)
参考:
要刷新所有微服务的配置属性,您可以通过消息代理(Spring Cloud Bus)将更改发布到所有微服务。
参考:
| 归档时间: |
|
| 查看次数: |
8695 次 |
| 最近记录: |