Spring配置客户端没有';如果配置服务器在初始启动期间关闭,则不会刷新
我正在用一个barebones 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
- 当启动时无法访问配置服务器时,客户端将使用本地打包的属性启动。(我在application.yml中拥有与客户端应用程序捆绑的属性)
- 与本地打包版本相比,Git后端具有不同的属性值。配置服务器知道git中的更改(通过直接连接到配置服务器确认)
- 我打开配置服务器并在客户端应用程序上执行POST-to/refresh端点
- 客户端应用程序不知道配置服务器中的新属性
- 客户端应用程序启动并成功连接到配置服务器。我看到客户机应用程序已经成功地从配置服务器获取了值
- 我在Git中进行更改,并在客户端应用程序上调用/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和