0Pricing
Spring Boot 4 Microservices & REST APIs · Leçon

Clients de configuration

Utilisez la configuration centralisée dans vos services.

Clients de configuration est une leçon Spring Boot 4 Microservices & REST APIs gratuite sur CoddyKit. Ceci est la leçon 3 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Spring Boot 4 Microservices & REST APIs, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Spring Boot 4 Microservices & REST APIs comprend 4 leçons au total.

Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.

Turning a service into a client

A microservice becomes a Config Client by adding the client starter and telling it where the Config Server is. It then fetches its config at startup.

Adding the client dependency

Add spring-cloud-starter-config to the service.

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

spring.config.import

Modern Spring Boot uses spring.config.import to point at the Config Server, replacing the old bootstrap.yml approach.

# application.yml of the client
spring:
  application:
    name: orders
  config:
    import: "configserver:http://localhost:8888"

How the name maps to config

The client's spring.application.name selects which files the server returns. Name it orders and you get orders.yml (plus shared and profile files).

Selecting a profile

The active profile decides which profile-specific file is layered on top. Set it as usual.

spring:
  profiles:
    active: prod
# -> server returns orders.yml + orders-prod.yml merged

Optional vs required import

By default the import is required - the app fails to start if the server is down. Mark it optional: to allow startup with local config as fallback.

spring:
  config:
    import: "optional:configserver:http://localhost:8888"

Using the fetched values

Once imported, remote properties behave like any other - inject with @Value or bind to a @ConfigurationProperties class.

@Component
public class GreetingService {
    @Value("${app.greeting}")
    private String greeting; // value comes from the config server
}

Type-safe binding

For groups of related settings, bind to a class. This is cleaner and validated.

@ConfigurationProperties(prefix = "app")
public class AppProps {
    private String greeting;
    // getters/setters
}

Discovering the server (optional)

Instead of a hardcoded URL, the client can find the Config Server via a discovery service (Eureka). Enable discovery-first lookup and reference the server by service id.

spring:
  cloud:
    config:
      discovery:
        enabled: true
        service-id: config-server

Fail-fast and retry

Enable fail-fast so a client refuses to start with missing config, and add the retry starter so transient server outages are retried instead of crashing the client.

spring:
  cloud:
    config:
      fail-fast: true
      retry:
        max-attempts: 6

Property precedence

Remote config from the server generally takes precedence over the client's local application.yml, so central values win - keep only safe defaults locally.

Quick Check

Check your client-setup knowledge.

Recap

You wired up a client:

  • Add spring-cloud-starter-config
  • Point at the server with spring.config.import
  • spring.application.name + active profile select the files
  • Use optional:, fail-fast and retry to control startup behavior

Questions Fréquemment Posées

La leçon « Clients de configuration » est-elle gratuite ?

Oui — le texte complet de « Clients de configuration » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Spring Boot 4 Microservices & REST APIs, passe à CoddyKit PRO. Le cours Spring Boot 4 Microservices & REST APIs comprend 4 leçons au total.

Qu'est-ce que j'apprendrai dans « Clients de configuration » ?

Utilisez la configuration centralisée dans vos services. Tu pratiques Spring Boot 4 Microservices & REST APIs avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.

Dois-je avoir de l'expérience pour commencer Spring Boot 4 Microservices & REST APIs ?

Aucune expérience préalable n'est requise. Spring Boot 4 Microservices & REST APIs sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 3 sur 4.

Combien de temps prend la leçon « Clients de configuration » ?

La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.

Peux-tu écrire et exécuter du code dans cette leçon Spring Boot 4 Microservices & REST APIs ?

Oui. Chaque leçon Spring Boot 4 Microservices & REST APIs inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.

Toutes les leçons de ce cours

  1. Le serveur de configuration
  2. Configuration gérée par Git
  3. Clients de configuration
  4. Actualiser la configuration à l'exécution
← Retour à Spring Boot 4 Microservices & REST APIs