<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Spring Boot on YennJ12 Engineering Blog</title><link>https://yennj12.js.org/yennj12_blog_V4/tags/spring-boot/</link><description>Recent content in Spring Boot on YennJ12 Engineering Blog</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Mon, 25 May 2026 09:00:00 +0800</lastBuildDate><atom:link href="https://yennj12.js.org/yennj12_blog_V4/tags/spring-boot/feed.xml" rel="self" type="application/rss+xml"/><item><title>購物車系統的高並發改造（一）：Virtual Threads、HikariCP 與 Redis 快取三管齊下</title><link>https://yennj12.js.org/yennj12_blog_V4/posts/shopping-cart-high-concurrency-part1-zh/</link><pubDate>Sun, 24 May 2026 09:00:00 +0800</pubDate><guid>https://yennj12.js.org/yennj12_blog_V4/posts/shopping-cart-high-concurrency-part1-zh/</guid><description>前言 電商系統有一個非常典型的流量特徵：平時風平浪靜，一到促銷活動瞬間湧入幾千上萬個並發請求。
如果你的購物車系統跑在默認的 Spring Boot 設定上，這個瞬間幾乎必定會讓系統崩潰——不是 OOM，就是資料庫連線耗盡，要不然就是 Tomcat 執行緒池打滿、請求開始逾時。
這篇文章深入剖析我們在 PR #227 中對一個 Spring Boot 購物車系統進行的高並發改造，涵蓋三個核心技術方向：
JDK 21 Virtual Threads：讓每個請求都跑在輕量級虛擬執行緒上 HikariCP 連線池調校：消除資料庫連線成為瓶頸的問題 Redis 分層快取：把熱點讀取從資料庫移到記憶體 系統架構概述 先看清楚我們在改什麼。這是一個標準的 Spring Boot 電商後端：
Client (Web/App) ↓ HTTP Spring Boot API (port 9999) ├── CartController → CartService → MySQL (cart table) ├── ProductController → ProductService → MySQL (products table) ├── OrderController → OrderService → MySQL (orders/order_items) │ → Stripe API (付款) ├── UserController → UserService → MySQL (users) └── AuthController → AuthenticationService → MySQL (auth_tokens) 技術棧：Spring Boot 3.</description></item><item><title>購物車系統的高並發改造（二）：Redisson 分散式鎖、讀寫分離路由與 Docker HA 水平擴展</title><link>https://yennj12.js.org/yennj12_blog_V4/posts/shopping-cart-high-concurrency-part2-zh/</link><pubDate>Mon, 25 May 2026 09:00:00 +0800</pubDate><guid>https://yennj12.js.org/yennj12_blog_V4/posts/shopping-cart-high-concurrency-part2-zh/</guid><description>前言 第一篇解決了系統的吞吐量問題：Virtual Threads 讓執行緒不再阻塞在 I/O 上，HikariCP 調校讓資料庫連線不再是瓶頸，Redis 快取讓熱點讀取從記憶體直接回傳。
但吞吐量提升後，反而暴露出一個更深層的問題：
並發請求同時寫入同一份資料，怎麼保證正確性？
想像雙十一活動開始的那一秒，同一個用戶的兩個 Tab 同時按下「加入購物車」；或者同一個人網路不穩，重試了兩次「立即結帳」——這兩種場景都會導致重複訂單或資料不一致。
這篇介紹 PR #228 帶來的三個進階改造：
Redisson 分散式鎖：防止同一用戶的並發寫入互相干擾 讀寫分離路由：把讀請求分流到 Replica，Primary 只處理寫入 Docker HA 水平擴展：Nginx + 多個 App 實例 + MySQL 主從複製 方案四：Redisson 分散式鎖 為什麼需要分散式鎖？ 第一篇的 CartService.addToCart() 在高並發下有一個隱患：
1// Part 1 的版本（沒有鎖） 2public void addToCart(AddToCartDto addToCartDto, Product product, User user) { 3 Cart cart = new Cart(product, addToCartDto.getQuantity(), user); 4 cartRepository.save(cart); // ← 多個執行緒可能同時執行這一行 5} 當同一個用戶同時發出兩個「加入購物車」請求時：
Thread A: new Cart(productX, qty=1, user) → save → 購物車有 1 個 productX Thread B: new Cart(productX, qty=1, user) → save → 購物車有 2 個 productX（重複！） cartRepository.</description></item><item><title>Spring Boot 多環境配置完整指南：開發、測試、生產環境管理</title><link>https://yennj12.js.org/yennj12_blog_V4/posts/spring-boot-multi-environment-configuration-guide-zh/</link><pubDate>Wed, 15 Oct 2025 10:00:00 +0000</pubDate><guid>https://yennj12.js.org/yennj12_blog_V4/posts/spring-boot-multi-environment-configuration-guide-zh/</guid><description>深入探討 Spring Boot 多環境配置管理，包括資料庫切換、Redis 配置、以及 Docker 容器化部署的完整實作指南。</description></item><item><title>Spring Boot 程式碼載入深度解析：從編譯到物件實例化完整流程</title><link>https://yennj12.js.org/yennj12_blog_V4/posts/spring-boot-code-loading-compilation-transformation-zh/</link><pubDate>Mon, 29 Sep 2025 09:50:40 +0800</pubDate><guid>https://yennj12.js.org/yennj12_blog_V4/posts/spring-boot-code-loading-compilation-transformation-zh/</guid><description>前言 Spring Boot 應用程式的啟動過程涉及複雜的程式碼載入、編譯轉換和物件實例化機制。本文將詳細分析從 Java 原始碼到執行期物件的完整轉換流程，幫助開發者深入理解 Spring Boot 的底層運作原理。
Java 程式碼編譯與載入流程 編譯階段：從原始碼到位元組碼 graph TB subgraph &amp;#34;編譯階段&amp;#34; JAVA[Java 原始碼&amp;lt;br/&amp;gt;.java 檔案] JAVAC[javac 編譯器] CLASS[位元組碼檔案&amp;lt;br/&amp;gt;.class 檔案] JAR[打包成 JAR&amp;lt;br/&amp;gt;.jar 檔案] end subgraph &amp;#34;載入階段&amp;#34; CLASSLOADER[類別載入器&amp;lt;br/&amp;gt;ClassLoader] JVM_MEMORY[JVM 記憶體區域] METHOD_AREA[方法區&amp;lt;br/&amp;gt;Class 資訊] HEAP[堆積記憶體&amp;lt;br/&amp;gt;物件實例] end JAVA --&amp;gt; JAVAC JAVAC --&amp;gt; CLASS CLASS --&amp;gt; JAR JAR --&amp;gt; CLASSLOADER CLASSLOADER --&amp;gt; JVM_MEMORY JVM_MEMORY --&amp;gt; METHOD_AREA JVM_MEMORY --&amp;gt; HEAP Java 編譯過程詳解 1/** 2 * Java 編譯過程示例 3 * 從原始碼到位元組碼的轉換 4 */ 5public class CompilationProcessDemo { 6 7 // 1.</description></item><item><title>AWS Load Balancers: Complete Guide - Application, Network, Gateway, and Classic Load Balancers Comparison with Implementation</title><link>https://yennj12.js.org/yennj12_blog_V4/posts/aws-load-balancer-complete-guide-comparison/</link><pubDate>Mon, 29 Sep 2025 08:28:29 +0800</pubDate><guid>https://yennj12.js.org/yennj12_blog_V4/posts/aws-load-balancer-complete-guide-comparison/</guid><description>🎯 Introduction AWS Load Balancers are critical components for building highly available, fault-tolerant, and scalable applications in the cloud. They distribute incoming traffic across multiple targets, ensuring optimal resource utilization and system reliability. This comprehensive guide explores all AWS Load Balancer types, their unique features, and when to use each one for maximum effectiveness.
Understanding the nuances between Application Load Balancer (ALB), Network Load Balancer (NLB), Gateway Load Balancer (GWLB), and Classic Load Balancer (CLB) is essential for architecting robust cloud solutions that can handle varying traffic patterns and requirements.</description></item><item><title>AWS API Gateway: Complete Guide with Load Balancer Comparison, Microservices Architecture, and Java Implementation</title><link>https://yennj12.js.org/yennj12_blog_V4/posts/aws-api-gateway-comprehensive-guide-comparison/</link><pubDate>Mon, 29 Sep 2025 08:19:47 +0800</pubDate><guid>https://yennj12.js.org/yennj12_blog_V4/posts/aws-api-gateway-comprehensive-guide-comparison/</guid><description>🎯 Introduction In modern distributed systems with dozens or hundreds of microservices, managing API traffic becomes increasingly complex. AWS API Gateway emerges as a critical component that acts as a single entry point for all client requests, solving major challenges in microservices architecture. This comprehensive guide explores API Gateway fundamentals, compares it with load balancers, and provides production-ready Java implementations.
API Gateway transforms chaotic microservices communication into organized, secure, and scalable architecture patterns that are essential for enterprise-grade applications.</description></item><item><title>Webhooks: Complete Guide with Java Implementation - Event-Driven Architecture, Real-Time Integrations, and Best Practices</title><link>https://yennj12.js.org/yennj12_blog_V4/posts/webhooks-comprehensive-guide-java-implementation/</link><pubDate>Mon, 29 Sep 2025 08:06:11 +0800</pubDate><guid>https://yennj12.js.org/yennj12_blog_V4/posts/webhooks-comprehensive-guide-java-implementation/</guid><description>🎯 Introduction Webhooks are HTTP callbacks that enable real-time, event-driven communication between applications. Instead of continuously polling for updates, webhooks allow systems to push data immediately when events occur. This comprehensive guide explores webhook architecture, compares different integration approaches, and provides production-ready Java implementations with real-world examples from Stripe, Shopify, and GitHub.
Webhooks have become essential for modern distributed systems, enabling efficient, scalable, and responsive integrations that power everything from payment processing to CI/CD pipelines and e-commerce automation.</description></item><item><title>Redis Sentinel: Complete High Availability Setup Guide with Java Integration and Monitoring</title><link>https://yennj12.js.org/yennj12_blog_V4/posts/redis-sentinel-high-availability-setup-guide/</link><pubDate>Mon, 29 Sep 2025 07:54:22 +0800</pubDate><guid>https://yennj12.js.org/yennj12_blog_V4/posts/redis-sentinel-high-availability-setup-guide/</guid><description>🎯 Introduction Redis Sentinel provides high availability and monitoring for Redis deployments. It&amp;rsquo;s a distributed system that monitors Redis master and replica instances, performs automatic failover, and acts as a configuration provider for clients. This comprehensive guide covers Redis Sentinel architecture, setup procedures, Java integration, and production best practices.
Redis Sentinel solves critical production challenges including automatic failover, service discovery, and configuration management, making it essential for mission-critical applications that require high availability and minimal downtime.</description></item><item><title>SpringDataPlatform: Apache Flink Management System</title><link>https://yennj12.js.org/yennj12_blog_V4/posts/springdataplatform-flink-management-system/</link><pubDate>Sat, 06 Sep 2025 14:46:19 +0800</pubDate><guid>https://yennj12.js.org/yennj12_blog_V4/posts/springdataplatform-flink-management-system/</guid><description>🎯 專案概述 SpringDataPlatform 是一個功能完整的企業級大數據平台，專為 Apache Flink 任務管理而設計。這個全端專案整合了現代化的 Web 技術棧，提供直觀的使用者介面來管理和監控分散式數據處理工作流程。
🏗️ 系統架構 graph TB A[Vue.js 前端] --&amp;gt; B[Nginx 反向代理] B --&amp;gt; C[Spring Boot 後端] C --&amp;gt; D[Apache Flink 叢集] C --&amp;gt; E[Apache Zeppelin] D --&amp;gt; F[任務執行引擎] E --&amp;gt; G[互動式筆記本] subgraph &amp;#34;核心功能&amp;#34; H[JAR 任務提交] I[SQL 任務提交] J[任務狀態監控] K[叢集狀態監控] end C --&amp;gt; H C --&amp;gt; I C --&amp;gt; J C --&amp;gt; K 🛠️ 技術架構 前端技術棧 框架：Vue.js 2.x 路由：Vue Router HTTP 客戶端：Axios UI 增強：SweetAlert2 語法高亮：Highlight.</description></item><item><title>SAGA Pattern: Managing Distributed Transactions in Spring Boot Microservices</title><link>https://yennj12.js.org/yennj12_blog_V4/posts/saga-pattern-distributed-transactions-spring-boot/</link><pubDate>Tue, 28 Jan 2025 01:00:00 +0800</pubDate><guid>https://yennj12.js.org/yennj12_blog_V4/posts/saga-pattern-distributed-transactions-spring-boot/</guid><description>🎯 Introduction In the era of microservices architecture, managing transactions across multiple services presents significant challenges. Traditional distributed transaction mechanisms like Two-Phase Commit (2PC) often lead to tight coupling, reduced availability, and poor performance. The SAGA Pattern emerges as a powerful alternative, providing a way to manage distributed transactions through a sequence of local transactions, each with compensating actions for rollback scenarios.
📚 What is the SAGA Pattern? 🔍 Core Concepts The SAGA pattern is a design pattern for managing long-running distributed transactions across multiple microservices.</description></item><item><title>Data Consistency Patterns in Java Enterprise Applications</title><link>https://yennj12.js.org/yennj12_blog_V4/posts/data-consistency-patterns-java-enterprise-applications/</link><pubDate>Tue, 28 Jan 2025 00:00:00 +0800</pubDate><guid>https://yennj12.js.org/yennj12_blog_V4/posts/data-consistency-patterns-java-enterprise-applications/</guid><description>🎯 Introduction Data consistency is one of the most critical challenges in modern Java enterprise applications. As systems scale and become distributed, maintaining data integrity while ensuring performance becomes increasingly complex. This comprehensive guide explores practical data consistency patterns implemented in real-world Java applications, complete with case studies, implementation details, and detailed trade-off analysis.
📊 The Data Consistency Challenge 🔍 Understanding Data Consistency Levels Data consistency refers to the guarantee that all nodes in a distributed system see the same data at the same time.</description></item></channel></rss>