首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring云-刷新范围-获取spring的配置属性的运行时值

Spring云-刷新范围-获取spring的配置属性的运行时值
EN

Stack Overflow用户
提问于 2021-03-03 11:13:51
回答 1查看 542关注 0票数 1

我希望使用弹簧执行器https://docs.spring.io/spring-boot/docs/current/actuator-api/htmlsingle/#env公开spring配置属性的当前值。

GET /actuator/env/{props}

我有两项服务:

service

  • Application服务
  • Cloud config

云配置有两个配置:maximum-upload-allow = 1Mfile-type = png

应用程序服务从云-config服务加载这些信任。

像这样:

代码语言:javascript
复制
@Configuration @Getter
public class ApplicationConfigurationProperty {
  @Value("${maximum-upload-allow}")
  private String maximumImageSize;
}

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

  • I也可以通过GET /actuator/env/maximum-upload-allow (1M)和GET /actuator/env/file-type (png)

获得我的配置

现在当我更新配置值maximum-upload-allow = 2Mfile-type = jpg

然后我通过调用总线刷新https://cloud.spring.io/spring-cloud-static/spring-cloud-bus/2.1.4.RELEASE/multi/multi__bus_endpoints.html来刷新范围。

我希望看到使用弹簧执行器的配置如下:

GET /actuator/env/maximum-upload-allow => 1M (因为没有刷新范围)

GET /actuator/env/file-type => jpg (我标记为复习镜)

但是实际上,弹簧执行器返回两个新值(2M和jpg)。

问:我如何获得我的运行时值的最大上传-允许是1米(当前的值,因为这里没有RefreshScope?

-更新

代码语言:javascript
复制
@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

提前谢谢你。

EN

回答 1

Stack Overflow用户

发布于 2021-03-04 19:51:23

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66455893

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档