Java 捕获spring@RefreshScope bean';在长时间运行的进程中刷新之前
我正在构建一个微服务系统,并使用SpringCloudConfig进行集中式配置,通过GithubWebhook自动刷新 一切正常,除了在某些情况下,我们需要bean的值在整个过程中保持不变Java 捕获spring@RefreshScope bean';在长时间运行的进程中刷新之前,java,spring,spring-cloud,spring-cloud-config,Java,Spring,Spring Cloud,Spring Cloud Config,我正在构建一个微服务系统,并使用SpringCloudConfig进行集中式配置,通过GithubWebhook自动刷新 一切正常,除了在某些情况下,我们需要bean的值在整个过程中保持不变 例如,这样的代码将结束,如果在进程的中间出现刷新,则客户端收到更新的值: @RefreshScope @ConfigurationProperties @Component @Getter @Setter public class ServiceConfig { @Value("${exa
例如,这样的代码将结束,如果在进程的中间出现刷新,则客户端收到更新的值:
@RefreshScope
@ConfigurationProperties
@Component
@Getter
@Setter
public class ServiceConfig {
@Value("${example.property}")
private String exampleProperty;
}
@RestController
@RequestMapping("/department")
public class DepartmentController {
@Autowired
private ServiceConfig serviceConfig;
@GetMapping("/config")
public ResponseEntity<String> getConfig() {
return ResponseEntity.ok(serviceConfig.getExampleProperty());
}
@GetMapping("/config-delayed")
public ResponseEntity<String> getConfigWithDelay() throws InterruptedException {
Thread.sleep(30000L);
return ResponseEntity.ok(serviceConfig.getExampleProperty());
}
}
@RefreshScope
@配置属性
@组成部分
@吸气剂
@塞特
公共类ServiceConfig{
@值(“${example.property}”)
私有字符串示例属性;
}
@RestController
@请求映射(“/部门”)
公共课系主任{
@自动连线
私有服务配置服务配置;
@GetMapping(“/config”)
公共响应属性getConfig(){
返回ResponseEntity.ok(serviceConfig.getExampleProperty());
}
@GetMapping(“/config delayed”)
public ResponseEntity getConfigWithDelay()引发InterruptedException{
线程。睡眠(30000L);
返回ResponseEntity.ok(serviceConfig.getExampleProperty());
}
}
我知道在线程睡眠之前添加一个String value=serviceConfig.getExampleProperty()
应该可以工作,但是在一个包含许多方法调用的复杂场景中,控制和维护将非常困难
有什么简单的方法可以做到这一点吗?我们正处于项目的设计阶段,因此欢迎spring之外支持此行为的其他配置管理解决方案