首页 文章

如果Config-Server在初始启动期间关闭,则Spring Config-Client不会刷新

提问于
浏览
1

我正在使用准系统Spring Cloud 配置服务器和客户端应用程序进行测试 . 在config-server最初关闭后,我执行了刷新方案(通过在客户端应用程序上调用/刷新 endpoints ) . 这是我发现的

  • 在启动时无法访问config-server时,客户端启动本地打包的属性 . (我在application.yml中的属性与客户端应用程序捆绑在一起)

  • 与本地打包版本相比,Git后端具有不同的属性值 . 配置服务器知道git中的更改(通过直接连接到config-server确认)

  • 我调出config-server并在客户端应用程序上执行POST到/ refresh endpoints .

  • 客户端应用程序不知道config-server中的新属性 .

在第二个用例中

  • 客户端应用程序启动并成功连接到config-server . 我看到来自config-server的值已成功获取客户端应用程序

  • 我在Git中进行了更改,并在客户端应用程序上调用/ refresh endpoints . 属性已成功刷新 .

此时,如果客户端应用程序最初启动而无法成功连接到config-server,则/ refresh似乎不起作用 . 如果在客户端应用程序启动时无法访问config-server,我这样做是为了测试客户端应用程序的回退策略 . (回退策略是在启动时无法使用config-server时使用本地打包的属性 . 如果config-server可用,则覆盖本地属性) . 任何指针说明为什么这不起作用以及我能做些什么不同?提前致谢 .

Edit

Server-Code

@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}

Client-Code

@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;
    }

}

bootstrap.yml(在配置客户端应用程序上)

spring:
  application:
    name: configclient
  cloud:
    config:
      uri: http://localhost:8888
management:
  security:
    enabled: false
logging:
  config: classpath:logback.xml
server:
  port: 8000

application.yml

message:
  greeting: Hello from Local!

Config in Git (通过配置服务器提供)

message:
  greeting: Hello from Git-Edited!

1 回答

  • 2

    根据spring-cloud-config文档 -

    如果您希望应用程序启动时配置服务器偶尔可用,您可以要求它在发生故障后继续尝试 . 首先,您需要设置spring.cloud.config.failFast = true,然后您需要在类路径中添加spring-retry和spring-boot-starter-aop . 默认行为是重试6次,初始退避间隔为1000毫秒,指数乘数为1.1,以便后续退避 . 您可以使用spring.cloud.config.retry . *配置属性配置这些属性(和其他属性) .

    参考 - > http://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.3.1.RELEASE/

相关问题