Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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配置客户端没有';如果配置服务器在初始启动期间关闭,则不会刷新_Spring_Spring Boot_Spring Cloud_Spring Cloud Config - Fatal编程技术网

Spring配置客户端没有';如果配置服务器在初始启动期间关闭,则不会刷新

Spring配置客户端没有';如果配置服务器在初始启动期间关闭,则不会刷新,spring,spring-boot,spring-cloud,spring-cloud-config,Spring,Spring Boot,Spring Cloud,Spring Cloud Config,我正在用一个barebones Spring云配置服务器和一个客户端应用程序运行一个测试。我执行了一个刷新场景(通过在客户端应用程序上调用/刷新端点) 配置服务器最初关闭后。这是我发现的 当启动时无法访问配置服务器时,客户端将使用本地打包的属性启动。(我在application.yml中拥有与客户端应用程序捆绑的属性) 与本地打包版本相比,Git后端具有不同的属性值。配置服务器知道git中的更改(通过直接连接到配置服务器确认) 我打开配置服务器并在客户端应用程序上执行POST-to/refre

我正在用一个barebones Spring云配置服务器和一个客户端应用程序运行一个测试。我执行了一个刷新场景(通过在客户端应用程序上调用/刷新端点) 配置服务器最初关闭后。这是我发现的

  • 当启动时无法访问配置服务器时,客户端将使用本地打包的属性启动。(我在application.yml中拥有与客户端应用程序捆绑的属性)
  • 与本地打包版本相比,Git后端具有不同的属性值。配置服务器知道git中的更改(通过直接连接到配置服务器确认)
  • 我打开配置服务器并在客户端应用程序上执行POST-to/refresh端点
  • 客户端应用程序不知道配置服务器中的新属性
在第二个用例中

  • 客户端应用程序启动并成功连接到配置服务器。我看到客户机应用程序已经成功地从配置服务器获取了值
  • 我在Git中进行更改,并在客户端应用程序上调用/refresh端点。属性已成功刷新
此时,如果客户端应用程序最初启动时无法成功连接到配置服务器,则/refresh似乎不起作用。我这样做是为了测试 如果在客户端应用程序启动时无法访问配置服务器,则客户端应用程序的回退策略。(回退策略是具有本地打包的属性 如果配置服务器在启动时不可用,将使用该选项。如果配置服务器可用,则覆盖本地属性)。是否有任何指示说明这不起作用,以及 我能做什么不同的事?提前谢谢

编辑

服务器代码

@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}
@RestController
@RefreshScope
@Component
public class Greeter {
    @Value("${message.greeting}")
    String greeting;

    @RequestMapping(value = "/",produces = "application/json")
    public List<String> index(){
        List<String> env = Arrays.asList("message.greeting: " + greeting);
        return env;
    }

}
客户端代码

@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}
@RestController
@RefreshScope
@Component
public class Greeter {
    @Value("${message.greeting}")
    String greeting;

    @RequestMapping(value = "/",produces = "application/json")
    public List<String> index(){
        List<String> env = Arrays.asList("message.greeting: " + greeting);
        return env;
    }

}
application.yml

message:
  greeting: Hello from Local!
Git中的配置(通过配置服务器提供)


根据spring云配置文档-

如果您预计配置服务器可能偶尔不可用 当你的应用程序启动时,你可以要求它在失败后继续尝试。 首先需要将spring.cloud.config.failFast设置为true,然后 需要将spring retry和spring boot starter aop添加到您的 类路径。默认行为是使用初始值重试6次 回退间隔为1000ms,指数乘数为1.1 随后的退避。您可以配置这些属性(以及其他属性) 使用spring.cloud.config.retry.*配置属性


参考->

您能用代码和单独的问题进行解释吗?添加了代码sample@ThamiraLakmal我没有看到你昨天发布的解决方案。你把它拿走了吗?是的!因为它不是基于你的具体问题。我添加了执行器并尝试解决问题。但不要刷新它。如果您需要其他场景的一些代码,请使用low和