【发布时间】:2020-02-27 03:39:42
【问题描述】:
我们有一个在 PCF 中运行的 Spring Boot 应用程序,它从应用程序中读取 PCF 环境变量(CF_INSTANCE_INDEX、CF_INSTANCE_ADDR、..)。基于这些变量,我们正在尝试实现调度程序的逻辑。在运行此调度程序时,这些变量的值可能已更改。有没有办法在运行时刷新/重新加载具有 env 值的 bean?
我们在配置属性 bean 上使用了 @RefreshScope 注释。
@Configuration
@RefreshScope
public class PcfEnvProperties{
@Value("${CF_INSTANCE_INDEX}")
private int intanceIndex;
@Value("${CF_INSTANCE_ADDR}")
private String intanceAddr;
...
}
并使用刷新
context.getBean(RefreshScope.class).refresh("PcfEnvProperties");
PcfEnvProperties pcfEnv = context.getBean(PcfEnvProperties.class);
但它不会将最近更改的环境变量加载到正在运行的应用程序中。关于如何做到这一点的任何想法?
【问题讨论】:
标签: java spring spring-boot pcf