繁体   English   中英

spring 启动,无法在运行时使用 spring 云配置更改属性值,@RefreshScope 不起作用

[英]spring boot, Not able to change the properties value at runtime using spring cloud config , @RefreshScope doesn't work

我正在使用 spring 云配置在运行时更改属性值,而无需重新启动应用程序。

我有一个具有不同配置文件的存储库,并且基于配置文件,我有多个应用程序用完一个存储库。

我有一个带有@Profile 注释之一的服务 class,

@Service
@Slf4j
@Profile("change-feed")
@RefreshScope
public class ProcessorFeedService extends ProcessorService {

private final boolean toggle;
private final FeedPublisher publisher;

public ProcessorFeedService(FeedPublisher publisher,
                                           @Value("${feed.toggle}") boolean toggle) {
    this.publisher = publisher;
    this.toggle = toggle;
}

public void handler(List<JsonNode> docs) {
    for (JsonNode document : docs) {
        try {
            if (toggle) {
                // do something
                publisher.publish();
            } else {
                // do something else
                inventoryChangePublisher.publish(document);
            }
        } catch (Exception ex) {
            log.error("Exception occurred while processing {}", document.toString(), ex);
        }
    }
   }
  }

我有一个“ application-change-feed ”属性文件和另一个应用程序测试文件,其中( application-test )在云配置存储库中有这个feed.toggle属性值。

application.properties 文件具有这些属性以启用刷新端点和所有

management.endpoints.web.exposure.include=info,health,env,refresh,bindings
management.endpoint.health.show-details=always
management.health.binders.enabled=true
spring.profiles.active=test
spring.profiles.include=change-feed

更改云配置文件中的属性值后,点击此刷新端点https://{url}/actuator/refresh它会返回更改后的属性。 但它并不反映应用程序中的更新值。 应用程序只选择旧的。

我究竟做错了什么?

刷新 Scope 通常适用于使用@Configuration注释的类

来自 spring 文档

Spring 文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM