由 Git 支持的配置
将配置版本化并存储在 Git 仓库中
由 Git 支持的配置 是 CoddyKit 上的免费 Spring Boot 4 Microservices & REST APIs 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Spring Boot 4 Microservices & REST APIs 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Spring Boot 4 Microservices & REST APIs 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Why Git as the backend
Storing configuration in Git gives you version history, code review, and rollback. The Config Server simply reads files from a configured repository.
The config repo layout
Each service has one or more YAML/properties files named after its application name, optionally with a profile suffix.
// config-repo/
// application.yml (shared by all)
// orders.yml (orders, default profile)
// orders-prod.yml (orders, prod profile)
// inventory.ymlShared application.yml
A file literally named application.yml holds defaults applied to every client. Put cross-cutting settings (logging, common URLs) here.
Profile-specific overrides
Profile files like orders-prod.yml override the base orders.yml for that profile. The server merges them, with the profile file taking precedence.
Pointing the server at the repo
Set the Git URI on the server. For private repos add credentials or an SSH key.
spring:
cloud:
config:
server:
git:
uri: https://github.com/acme/config-repo
username: ci-bot
password: ${GIT_TOKEN}Choosing a branch (label)
The Git label defaults to main/master but can be any branch or tag. Clients can request a specific label, enabling per-environment branches.
server:
cloud:
config:
server:
git:
default-label: release-2026Search paths in the repo
If config lives in subfolders, set search-paths so the server looks in the right places. Placeholders like {application} are supported.
spring:
cloud:
config:
server:
git:
uri: https://github.com/acme/config-repo
search-paths: "{application}"Cloning behavior
The server clones the repo on first request (or eagerly). With clone-on-start: true it fails fast at boot if the repo is unreachable, surfacing misconfiguration early.
spring:
cloud:
config:
server:
git:
clone-on-start: truePicking up new commits
On each client request the server checks for new commits. So pushing a change to the repo makes it available - clients still need to be refreshed to apply it (covered later).
Multiple repos
You can map different applications or patterns to different repositories, e.g. keep secrets in a separate, tightly-controlled repo.
spring:
cloud:
config:
server:
git:
uri: https://github.com/acme/general-config
repos:
secure:
pattern: payments-*
uri: https://github.com/acme/secure-configKeeping secrets safe
Even in Git, never commit plaintext secrets. Use the server's {cipher} encryption or an external secret manager, and restrict repo access.
Quick Check
Verify your Git-backend understanding.
Recap
You backed config with Git:
- Files named by application + optional profile suffix
application.yml= shared defaults;app-profile.ymloverrides- Configure URI, label (branch), search-paths and credentials
- Keep secrets encrypted, never plaintext
常见问题解答
「由 Git 支持的配置」课时是免费的吗?
是的 — 「由 Git 支持的配置」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Spring Boot 4 Microservices & REST APIs 课程的其余内容,请升级到 CoddyKit PRO。 Spring Boot 4 Microservices & REST APIs 课程共包含 4 节课。
「由 Git 支持的配置」这节课中我会学到什么?
将配置版本化并存储在 Git 仓库中 你通过在浏览器中直接运行的动手代码来练习 Spring Boot 4 Microservices & REST APIs,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Spring Boot 4 Microservices & REST APIs 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Spring Boot 4 Microservices & REST APIs 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。
「由 Git 支持的配置」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Spring Boot 4 Microservices & REST APIs 课中编写并运行代码吗?
能。每节 Spring Boot 4 Microservices & REST APIs 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。