In some cases, you may want to fail startup of a Spring Boot application if it cannot connect to the Config Server. You can do that setting the bootstrap configuration property spring.cloud.config.fail-fast=true. In this way the client startup halt with an Exception.

Config server may occasionally be unavailable when your application starts, you can make it keep trying after a failure. Can be useful for an application retry until the config server become reachable.

The complete set of configurable properties is:

  • spring.cloud.config.fail-fast
  • spring.cloud.config.retry.max-attempts
  • spring.cloud.config.retry.max-interval
  • spring.cloud.config.retry.initial-interval
  • spring.cloud.config.retry.multiplier

Below an example of configuration you can do in the bootstrap.properties file of your Spring Boot application:

spring.cloud.config.fail-fast=true
spring.cloud.config.retry.max-attempts=5
spring.cloud.config.retry.initial-interval=1500
spring.cloud.config.retry.multiplier=1.5

The configured behaviour is to retry 5 times with an initial backoff interval of 1000ms and an exponential multiplier of 1.5 for subsequent backoffs.

Default values are:

long initialInterval = 1000;
/**
 * Multiplier for next interval.
 */
double multiplier = 1.1;
/**
 * Maximum interval for backoff.
 */
long maxInterval = 2000;
/**
 * Maximum number of attempts.
 */
int maxAttempts = 6;

Take care that you have the following dependencies in the classpath:

<dependency>
	<groupId>org.springframework.retry</groupId>
	<artifactId>spring-retry</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

References