Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 动态刷新springboot配置_Spring Boot_Spring Cloud_Spring Cloud Config_Spring Config - Fatal编程技术网

Spring boot 动态刷新springboot配置

Spring boot 动态刷新springboot配置,spring-boot,spring-cloud,spring-cloud-config,spring-config,Spring Boot,Spring Cloud,Spring Cloud Config,Spring Config,一旦我们更改.properties文件,有没有办法刷新springboot配置 我遇到了springcloudconfig,许多文章/博客建议在分布式环境中使用它。我的springboot应用程序有许多部署,但它们彼此不相关或相互依赖。我还研究了一些解决方案,他们建议提供rest端点,以便在不重新启动应用程序的情况下手动刷新配置。但是,每当我更改.properties文件时,我都希望动态刷新配置,而无需手动干预 非常感谢您的指导/建议。您可以使用Spring Cloud配置“服务器”,并让它向您

一旦我们更改
.properties
文件,有没有办法刷新
springboot
配置

我遇到了
springcloudconfig
,许多文章/博客建议在分布式环境中使用它。我的
springboot
应用程序有许多部署,但它们彼此不相关或相互依赖。我还研究了一些解决方案,他们建议提供rest端点,以便在不重新启动应用程序的情况下手动刷新配置。但是,每当我更改
.properties
文件时,我都希望动态刷新配置,而无需手动干预


非常感谢您的指导/建议。

您可以使用Spring Cloud配置“服务器”,并让它向您的Spring Cloud客户端发出属性文件已更改的信号。请参见此示例:

在封面下,它正在做一个广播,然后向您的客户广播:

    @Scheduled(fixedRateString = "${spring.cloud.config.server.monitor.fixedDelay:5000}")
    public void poll() {
        for (File file : filesFromEvents()) {
            this.endpoint.notifyByPath(new HttpHeaders(), Collections
                    .<String, Object>singletonMap("path", file.getAbsolutePath()));
        }
    }

在这种情况下使用Scheduled是否有效?我试图通过这种方法来理解我的应用程序的过载(如果有)。我无法重新启动应用程序来刷新配置更改。但我希望通过使用可用选项来动态刷新,从而尽可能保持它的效率。我建议的第一个选项(使用Spring Config Server)可能是您最好的方法。它基本上会向您的应用程序发送一个事件。不过,缺点是,如果您不想让单独的服务器运行,那么它是“低效的”。谢谢@Dovmo。我会尝试第一种选择,看看它是否合适
@Component
public class MyRefresher {

    @Autowired
    private ContextRefresher contextRefresher;

    @Scheduled(fixedDelay=5000)
    public void myRefresher() {
        // Code here could potentially look at the properties file 
        // to see if it changed, and conditionally call the next line...
        contextRefresher.refresh();
    } 
}