如何从Spring Boot应用程序更改consul K / V Store中的值

问题描述 投票:1回答:1

我在Spring Boot 2应用程序中使用Consul的Key / Value Store作为PropertySource。 (org.springframework.cloud:spring-cloud-starter-consul-config)

我可以使用@ConfigurationProperties从K / V商店中读取属性,当我通过Consul Web界面更改值时,甚至可以使用@RefreshScope更新它们。

但我确实有一些动态属性可以在应用程序中更改。如何将这些更改传播到Consul,以便实际更改值。我试图使用Setter作为属性,但这并未改变Consul中的值。

java spring-boot consul
1个回答
1
投票

使用此代码设置KV值。创建私有变量。

@Autowired
private ConsulClient consulClient;

使用setKVValue()方法更改KV。

consulClient.setKVValue("key", "value")
© www.soinside.com 2019 - 2024. All rights reserved.