springcloud-refresh scope-get springbean配置属性的运行时值

vngu2lb8  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(284)

我想使用springactuator公开springbean的configuration属性的当前值https://docs.spring.io/spring-boot/docs/current/actuator-api/htmlsingle/#env GET /actuator/env/{props} 我有两项服务:
云配置服务
应用服务
云配置有两种配置 maximum-upload-allow = 1M 以及 file-type = png 应用程序服务从云配置服务加载这些配置
比如:

@Configuration @Getter
public class ApplicationConfigurationProperty {
  @Value("${maximum-upload-allow}")
  private String maximumImageSize;
}

@Configuration  @RefreshScope  @Getter
public class FileConfigurationProperty {
  @Value("${file-type}")
  private String fileType;
}

我也可以通过 GET /actuator/env/maximum-upload-allow (1米)和 GET /actuator/env/file-type (巴布亚新几内亚)
现在当我更新配置值时 maximum-upload-allow = 2M 以及 file-type = jpg 然后我通过调用总线刷新来刷新作用域https://cloud.spring.io/spring-cloud-static/spring-cloud-bus/2.1.4.release/multi/multi__bus_endpoints.html
我想看看我的配置使用Spring驱动器是: GET /actuator/env/maximum-upload-allow =>1m(因为没有范围) GET /actuator/env/file-type =>jpg(我标记为refreshscope)
但实际上,Spring执行器返回两个新值(2m和jpg)
问:我如何才能得到我的最大上传允许运行时值是1m(当前值,因为这里没有refreshscope?
---更新

@Configuration @Setter @Getter @ConfigurationProperties
public class ApplicationConfigurationProperty {
  @Value("${maximum-upload-allow}")
  private String maximumImageSize;
}

此配置值在没有@refreshscope注解的情况下刷新
我认为这里提到的这些行为是正确的https://cloud.spring.io/spring-cloud-static/spring-cloud-bus/2.1.4.release/multi/multi__bus_endpoints.html
先谢谢你。

2nbm6dog

2nbm6dog1#

我发现一个简单的解决方案是实现一个新的执行器端点,即load@refreshscope并使用反射来读取bean的属性

相关问题