Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fail fast if a Spring application cannot connect to its config server

Tags:

java

spring

Consider you have a Spring application that gets its configuration from a config server. If it cannot connect to the config server, the application will continue to start but as all configurations are missing, it will eventually fail with a potentially misleading error.

Is it possible to configure Spring, so it immediately aborts when it cannot connect to its config server during startup?

like image 883
Philipp Claßen Avatar asked Nov 09 '16 15:11

Philipp Claßen


People also ask

What is the use of spring cloud config fail fast true?

failFast=true , and then you need to add spring-retry and spring-boot-starter-aop to your classpath. The default behaviour is to retry 6 times with an initial backoff interval of 1000ms and an exponential multiplier of 1.1 for subsequent backoffs. You can configure these properties (and others) using spring. cloud.

When a config client starts it binds to the config server through the?

7.1 Config First Bootstrap The default behavior for any application that has the Spring Cloud Config Client on the classpath is as follows: When a config client starts, it binds to the Config Server (through the spring.

How does Spring cloud Config server work?

Spring Cloud Config Server provides an HTTP resource-based API for external configuration (name-value pairs or equivalent YAML content). The server is embeddable in a Spring Boot application, by using the @EnableConfigServer annotation. Consequently, the following application is a config server: ConfigServer.


1 Answers

Set spring.cloud.config.failFast to true in your bootstrap.yml or bootstrap.properties file. Also, you can add -Dspring.cloud.config.failFast=true to the JVM arguments.

From the documentation

Config Client Fail Fast

In some cases, it may be desirable to fail startup of a service if it cannot connect to the Config Server. If this is the desired behavior, set the bootstrap configuration property spring.cloud.config.failFast=true and the client will halt with an Exception.

like image 172
Captain Man Avatar answered Oct 21 '22 03:10

Captain Man