Quick shutdown if Spring application cannot connect to its configuration server

You have a Spring application that gets its configuration from the configuration server. If it cannot connect to the configuration server, the application will continue to run, but as all configurations are missing, it will end up with a potentially misleading error.

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

+5
source share
2 answers

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

From the documentation

Client configuration crash fast

In some cases, it may be undesirable to start a service if it cannot connect to the configuration server. If this is the desired behavior, set the bootstrap configuration property spring.cloud.config.failFast=true , and the client will stop with an Exception.

+3
source

You can achieve this using the spring cloud components Spring Cloud Config Server and Spring Cloud Config Client .

1. spring cloud server

The server provides an HTTP resource API for external configuration (name-value pairs or equivalent YAML content). The server is easily integrated into the spring boot application using the @EnableConfigServer annotation. So, this application is a configuration server:

 //ConfigServer.java @SpringBootApplication @EnableConfigServer public class ConfigServer { public static void main(String[] args) { SpringApplication.run(ConfigServer.class, args); } } 


2. spring Cloud Config client

A spring A boot application can immediately use the spring configuration server (or other external property sources provided by the application developer) and will also receive additional useful functions related to environment change events.

Then on the client side of the configuration, you can quickly configure fail by setting the boot configuration property spring.cloud.config.failFast=true

Spring cloud documentation Client configuration not working

+2
source

Source: https://habr.com/ru/post/1259511/


All Articles