Spring Boot 4 Complete Guide · บทเรียน

การกำหนดค่ารวมศูนย์ด้วย Spring Cloud Config

จัดการการกำหนดค่าสำหรับไมโครเซอร์วิสจำนวนมากไว้ในที่เดียว ด้วย Spring Cloud Config Server และแหล่งคุณสมบัติภายนอก

บทเรียน 4 จาก 413 ขั้นตอน

การกำหนดค่ารวมศูนย์ด้วย Spring Cloud Config เป็นบทเรียน Spring Boot 4 Complete Guide ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Spring Boot 4 Complete Guide และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Spring Boot 4 Complete Guide มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

The Configuration Problem at Scale

With dozens of microservices, scattering properties across each one becomes unmanageable. Centralized configuration stores settings in one source that every service reads from.

What Is Spring Cloud Config?

Spring Cloud Config provides a Config Server that serves configuration to client services, typically backed by a Git repository for versioning and auditability.

Setting Up the Config Server

Annotate a Spring Boot app with @EnableConfigServer to turn it into a configuration hub.

@EnableConfigServer
@SpringBootApplication
public class ConfigServerApp {
}

Pointing to a Git Backend

Configure the server to read from a Git repo. Each service's properties live as files in that repo.

spring.cloud.config.server.git.uri=https://github.com/org/config-repo

File Naming Convention

Config files are named by application and profile, such as order-service-prod.yml. The server matches requests to the right file.

  • application.yml — shared defaults
  • order-service.yml — per service
  • order-service-prod.yml — per profile

Making a Service a Config Client

A client service adds the config client starter and declares which application name and Config Server to use.

spring.application.name=order-service
spring.config.import=configserver:http://localhost:8888

How Clients Fetch Config

On startup, the client contacts the Config Server, downloads its properties, and merges them into its environment before the rest of the app initializes.

Refreshing Without Restart

The @RefreshScope annotation lets beans pick up new values when you POST to the /actuator/refresh endpoint, avoiding full restarts.

@RefreshScope
@Component
public class FeatureFlags {
}

Securing Sensitive Values

Secrets like passwords should be encrypted. The Config Server supports encrypting values so the Git repo never stores plaintext credentials.

Profiles and Environments

By using profile-specific files, the same service binary picks up dev, staging, or prod settings simply by activating the matching profile.

Why This Pattern Wins

Centralized, versioned, refreshable config means you change a setting once, audit who changed it, and roll it out without rebuilding services.

Quick Check

Test your understanding of centralized configuration.

Recap

You set up a Config Server backed by Git, connected client services, used profile-specific files, and enabled live refresh with @RefreshScope. Centralized config keeps a fleet of microservices consistent and manageable.

เริ่มต้นได้ฟรี

เรียนรู้ Java ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
21
บทเรียน
84

คำถามที่พบบ่อย

บทเรียน “การกำหนดค่ารวมศูนย์ด้วย Spring Cloud Config” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การกำหนดค่ารวมศูนย์ด้วย Spring Cloud Config” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Spring Boot 4 Complete Guide ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Spring Boot 4 Complete Guide มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การกำหนดค่ารวมศูนย์ด้วย Spring Cloud Config”

จัดการการกำหนดค่าสำหรับไมโครเซอร์วิสจำนวนมากไว้ในที่เดียว ด้วย Spring Cloud Config Server และแหล่งคุณสมบัติภายนอก คุณปฏิบัติ Spring Boot 4 Complete Guide ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Spring Boot 4 Complete Guide หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Spring Boot 4 Complete Guide บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “การกำหนดค่ารวมศูนย์ด้วย Spring Cloud Config” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Spring Boot 4 Complete Guide นี้ได้ไหม

ได้ บทเรียน Spring Boot 4 Complete Guide ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. หลักการและการออกแบบไมโครเซอร์วิส
  2. การค้นหาและลงทะเบียนบริการ
  3. เกตเวย์ API ด้วย Spring Cloud Gateway
  4. การกำหนดค่ารวมศูนย์ด้วย Spring Cloud Config
← กลับไปที่ Spring Boot 4 Complete Guide