Le serveur de configuration
Diffusez la configuration depuis un serveur central.
Le serveur de configuration est une leçon Spring Boot 4 Microservices & REST APIs gratuite sur CoddyKit. Ceci est la leçon 1 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.
The configuration problem
In a microservices system, many services each need configuration. Duplicating application.yml everywhere is error-prone. Spring Cloud Config centralizes configuration in one server.
What the Config Server does
The Config Server is a small Spring Boot app that serves configuration to client services over HTTP, typically backed by a Git repository.
- One place to view and change config
- Versioned, auditable changes
Adding the server dependency
Create a new app and add spring-cloud-config-server.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>@EnableConfigServer
Annotate the main class with @EnableConfigServer to turn the app into a Config Server.
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApp {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApp.class, args);
}
}Pointing at a backend
The server needs a backend to read config from. The most common is a Git repo, set with spring.cloud.config.server.git.uri.
# application.yml of the server
spring:
cloud:
config:
server:
git:
uri: https://github.com/acme/config-repoRunning on a known port
Config Servers conventionally run on port 8888 so clients can find them with default settings.
server:
port: 8888How config is addressed
The server resolves config by application name and profile. A client named orders with profile prod maps to files like orders-prod.yml in the repo.
The server HTTP API
You can query the server directly. The path is /{application}/{profile} and it returns the merged properties as JSON.
// GET http://localhost:8888/orders/prod
// returns merged config for app=orders, profile=prodNative (filesystem) backend
For local development you can use a filesystem backend instead of Git via the native profile - convenient but not versioned.
spring:
profiles:
active: native
cloud:
config:
server:
native:
search-locations: file:./configSecuring the server
Config can contain secrets, so protect the server with HTTP Basic auth (Spring Security) and run it behind your private network. Clients then send credentials.
Encryption support
The server can store encrypted values (prefixed {cipher}) and decrypt them on the fly, so secrets are never stored in plaintext in the repo - provided a key is configured.
Quick Check
Check your Config Server fundamentals.
Recap
You stood up a Config Server:
- It centralizes config and serves it over HTTP
@EnableConfigServer+ a Git (or native) backend- Runs on port 8888 by convention
- Resolves config by application name and profile
Questions Fréquemment Posées
La leçon « Le serveur de configuration » est-elle gratuite ?
Oui — le texte complet de « Le serveur 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 « Le serveur de configuration » ?
Diffusez la configuration depuis un serveur central. 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 1 sur 4.
Combien de temps prend la leçon « Le serveur 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
- Le serveur de configuration
- Configuration gérée par Git
- Clients de configuration
- Actualiser la configuration à l'exécution