การเพิ่ม SpringDoc ในโครงงาน
สร้างเอกสาร OpenAPI โดยอัตโนมัติ
การเพิ่ม SpringDoc ในโครงงาน เป็นบทเรียน Spring Boot 4 Microservices & REST APIs ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Spring Boot 4 Microservices & REST APIs และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Spring Boot 4 Microservices & REST APIs มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Why document your API?
An API without docs is hard to consume. OpenAPI (formerly Swagger) is a standard, machine-readable description of your REST API that powers interactive docs, client generation and contract testing.
What SpringDoc does
SpringDoc OpenAPI inspects your Spring controllers at runtime and generates the OpenAPI spec automatically - no hand-written YAML needed.
- Reads your
@RestControllermappings - Serves the spec and a Swagger UI
Adding the starter (Maven)
Add the springdoc-openapi-starter-webmvc-ui dependency. The -ui variant bundles Swagger UI as well as the JSON spec.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.6.0</version>
</dependency>Adding the starter (Gradle)
The Gradle coordinates are the same artifact.
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0"WebMVC vs WebFlux
Pick the starter matching your stack:
- Servlet apps ->
springdoc-openapi-starter-webmvc-ui - Reactive apps ->
springdoc-openapi-starter-webflux-ui
Zero config to start
With just the dependency, start the app and SpringDoc auto-configures everything. You immediately get the generated spec and UI without writing any code.
The generated JSON endpoint
The raw OpenAPI document is served at /v3/api-docs by default. This JSON can feed code generators, Postman, or API gateways.
// GET http://localhost:8080/v3/api-docs
// returns the full OpenAPI 3 JSON documentThe Swagger UI endpoint
The interactive UI is at /swagger-ui.html. It lists every endpoint and lets you try requests in the browser.
// open http://localhost:8080/swagger-ui.htmlChanging the default paths
You can relocate the spec and UI via properties, useful behind a gateway or to avoid collisions.
# application.yml
springdoc:
api-docs:
path: /api-docs
swagger-ui:
path: /docs.htmlWhat gets detected automatically
SpringDoc infers a lot with no annotations: paths, HTTP methods, path/query params, request and response body schemas from your DTO classes, and response status codes.
Disabling in production (optional)
Some teams expose docs only in non-prod. Toggle with properties so the spec and UI are not served in production.
# disable everywhere
springdoc:
api-docs:
enabled: false
swagger-ui:
enabled: falseQuick Check
Confirm the basics of adding SpringDoc.
Recap
You bootstrapped API docs:
- SpringDoc generates the OpenAPI spec from your controllers
- Add
springdoc-openapi-starter-webmvc-ui(or webflux) - Spec at
/v3/api-docs, UI at/swagger-ui.html - Paths and enablement are configurable via properties
คำถามที่พบบ่อย
บทเรียน “การเพิ่ม SpringDoc ในโครงงาน” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การเพิ่ม SpringDoc ในโครงงาน” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Spring Boot 4 Microservices & REST APIs ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Spring Boot 4 Microservices & REST APIs มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การเพิ่ม SpringDoc ในโครงงาน”
สร้างเอกสาร OpenAPI โดยอัตโนมัติ คุณปฏิบัติ Spring Boot 4 Microservices & REST APIs ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Spring Boot 4 Microservices & REST APIs หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Spring Boot 4 Microservices & REST APIs บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “การเพิ่ม SpringDoc ในโครงงาน” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Spring Boot 4 Microservices & REST APIs นี้ได้ไหม
ได้ บทเรียน Spring Boot 4 Microservices & REST APIs ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การเพิ่ม SpringDoc ในโครงงาน
- การจัดทำเอกสารปลายทางและโมเดล
- การปรับแต่งข้อกำหนด OpenAPI
- Swagger UI