Statistics
33
Views
0
Downloads
0
Donations
Support
Share
Uploader

高宏飞

Shared on 2026-01-15

AuthorMoises Macero Garcia, Tarun Telang

This book will show you how to build Java-based microservices architecture using the popular Spring Boot framework by evolving a small monolith application to an event-driven architecture composed of several services. This third edition has been updated to cover Spring Boot 3, including its compatibility with Java 17 and Jakarta EE 10, and employs an incremental approach to teach the structure of microservices, test-driven development, and common patterns in distributed systems such as service discovery, load balancing, routing, centralized logs, per-environment configuration, and containerization. Authors Moisés Macero and Tarun Telang get the ball rolling by introducing you to the fundamentals of microservices and Spring Boot before walking you through the development of a basic Spring Boot application. You’ll then see how to build a front end using React, and learn how to use the data layer to read and write data from and to other systems via Spring Boot and its access to Spring Data and its available APIs. Putting together what you've learned thus far, you’ll begin to transform an application from a monolith to a microservice. This pragmatic approach will enable you to better grasp the benefits of using this type of software architecture, instead of keeping you distracted with theoretical concepts. The emphasis is on what matters most, starting with the minimum viable product, while maintaining the ability to adapt and improve your application as needed. After completing this book, you will have the foundational knowledge necessary to build your own microservice-based applications using Spring Boot.

Tags
No tags
ISBN: 1484297571
Publisher: Apress
Publish Year: 2023
Language: 英文
File Format: PDF
File Size: 8.2 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

(This page has no text content)
(This page has no text content)
(This page has no text content)
(This page has no text content)
Learn Microservices with Spring Boot 3 A Practical Approach Using Event- Driven Architecture, Cloud-Native Patterns, and Containerization Third Edition Moisés Macero García Tarun Telang Learn Microservices with Spring Boot 3: A Practical Approach Using Event-Driven Architecture, Cloud-Native Patterns, and Containerization, Third Edition Moisés Macero García Tarun Telang New York, NY, USA Hyderabad, Telangana, India ISBN-13 (pbk): 978-1-4842-9756-8 ISBN-13 (electronic): 978-1-4842-9757-5 https://doi.org/10.1007/978-1-4842-9757-5 Copyright © 2023 by Moisés Macero García and Tarun Telang
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Melissa Duffy Development Editor: Laura Berendson Coordinating Editor: Gryffin Winkler Copy Editor: Kezia Endsley Cover designed by eStudioCalamar Cover image by Image by James DeMers on Pixabay (www.pixabay.com) Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004, U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders- ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub (https://github.com/Apress). For more detailed information, please visit https://www. apress.com/gp/services/source-code. Paper in this product is recyclable This book is dedicated to my grandparents, parents, wife Nikita, and son Vihan. They have always been a source of inspiration and encouragement to me. It’s also for all of the software and technology creators who work hard to make our planet a better place to live. —Tarun Telang Table of Contents About the Authors ������������������������������ ������������������������������ ������������������������������ �������� xiii About the Technical Reviewer ������������������������������ ������������������������������ ���������������������xv Acknowledgments ������������������������������ ������������������������������ ������������������������������ �������xvii About this Book ������������������������������
������������������������������ ������������������������������ ������������������������������ ������������xix Chapter 1: Setting the Scene ������������������������������ ������������������������������ ������������������������ 1 Who Are You? ������������������������������ ������������������������������ ������������������������������ ������������������������������ �������� 3 How Is This Book Different from Other Books and Guides? ������������������������������ ���������������������������� 5 Learning: An Incremental Process ������������������������������ ������������������������������ ������������������������������ � 5 Is This a Guide or a Book? ������������������������������ ������������������������������ ������������������������������ ������������� 5 From Basics to Advanced Topics ������������������������������ ������������������������������ ������������������������������ ��������� 6
Skeleton with Spring Boot, the Professional Way ������������������������������ ������������������������������ �������� 7 Test-Driven Development ������������������������������ ������������������������������ ������������������������������ �������������� 7 Microservices ������������������������������ ������������������������������ ������������������������������ ������������������������������ �� 7 Event-Driven Systems ������������������������������ ������������������������������ ������������������������������ ������������������� 8 Nonfunctional Requirements ������������������������������ ������������������������������ ������������������������������ ��������� 8 Online Content ������������������������������ ������������������������������ ������������������������������ ������������������������������ ������ 9 ��������������������������
Summary�������������������������� ������������������������������ ������������������������������ ������������������������������ ������������������� 9 Chapter 2: Basic Concepts ������������������������������ ������������������������������ �������������������������� 11 Spring��������������������������� ������������������������������ ������������������������������ ������������������������������ ��������������������� 11 Spring Boot ������������������������������ ������������������������������ ������������������������������ ������������������������������ ��������� 16 Lombok and Java ������������������������������ ������������������������������ ������������������������������ ������������������������������ 18 Testing Basics ������������������������������ ������������������������������ ������������������������������ ������������������������������ ����� 21
Test-Driven Development ������������������������������ ������������������������������ ������������������������������ ������������ 21 Behavior-Driven Development ������������������������������ ������������������������������ ������������������������������ ����� 22 v Table of ConTenTs JUnit 5 ������������������������������ ������������������������������ ������������������������������ ������������������������������ ����������� 23 Mockito ������������������������������ ������������������������������ ������������������������������ ������������������������������ ���������� 23 AssertJ ������������������������������ ������������������������������ ������������������������������ ������������������������������ ���������� 27
Testing in Spring Boot ������������������������������ ������������������������������ ������������������������������ ����������������������� 28 Logging ������������������������������ ������������������������������ ������������������������������ ������������������������������ ��������������� 29 Summary and Achievements ������������������������������ ������������������������������ ������������������������������ ������������ 30 Chapter 3: A Basic Spring Boot Application ������������������������������ ����������������������������� 33 Setting Up the Development Environment ������������������������������ ������������������������������ ���������������������� 34 Java Development Kit 17 ������������������������������ ������������������������������ ������������������������������ ������������� 34 Integrated Development Environment (IDE) ������������������������������ ������������������������������
������������������������������ ��������������� 34 HTTPie ������������������������������ ������������������������������ ������������������������������ ������������������������������ ����������� 35 POST Request ������������������������������ ������������������������������ ������������������������������ ������������������������������ 36 cURL ������������������������������ ������������������������������ ������������������������������ ������������������������������ �������������� 36 The Skeleton Web App ������������������������������ ������������������������������ ������������������������������ ���������������������� 36 Spring Boot Autoconfiguration ������������������������������ ������������������������������ ������������������������������ ���������� 41
Three-Tier, Three-Layer Architecture ������������������������������ ������������������������������ ������������������������������ 47 Modeling the Domain ������������������������������ ������������������������������ ������������������������������ ������������������������ 50 Domain Definition and Domain-Driven Design ������������������������������ ������������������������������ ���������� 50 Domain Classes ������������������������������ ������������������������������ ������������������������������ ��������������������������� 52 Business Logic ������������������������������ ������������������������������ ������������������������������ ������������������������������ ���� 55 What You Need ������������������������������ ������������������������������ ������������������������������ ���������������������������� 55
Random Challenges ������������������������������ ������������������������������ ������������������������������ ��������������������� 55 Attempt Verification ������������������������������ ������������������������������ ������������������������������ ��������������������� 59 Presentation Layer ������������������������������ ������������������������������ ������������������������������ ���������������������������� 64 REST ������������������������������ ������������������������������ ������������������������������ ������������������������������ �������������� 64 REST APIs with Spring Boot ������������������������������ ������������������������������ ������������������������������ ��������� 65 Designing the APIs ������������������������������ ������������������������������ ������������������������������ ����������������������� 66
Your First Controller ������������������������������ ������������������������������ ������������������������������ ��������������������� 67 How Automatic Serialization Works ������������������������������ ������������������������������ ��������������������������� 69 Testing Controllers with Spring Boot ������������������������������ ������������������������������ ������������������������� 73 Summary and Achievements ������������������������������ ������������������������������ ������������������������������ ������������ 86 vi Table of ConTenTs Chapter 4: A Minimal Frontend with React ������������������������������ ������������������������������ � 89 A Quick Intro to React and Node ������������������������������ ������������������������������ ������������������������������ ������� 90
Setting Up the Development Environment ������������������������������ ������������������������������ ���������������������� 91 The React Skeleton ������������������������������ ������������������������������ ������������������������������ ��������������������������� 92 A JavaScript Client ������������������������������ ������������������������������ ������������������������������ ���������������������������� 94 The Challenge Component ������������������������������ ������������������������������ ������������������������������ ���������������� 96 The Main Structure of a Component ������������������������������ ������������������������������ �������������������������� 99 Rendering ������������������������������ ������������������������������ ������������������������������ ������������������������������ ���� 101 Integration with the App ������������������������������ ������������������������������
������������������������������ ������������������������������ ������������ 104 Running the Frontend the First Time ������������������������������ ������������������������������ ����������������������������� 105 Debugging ������������������������������ ������������������������������ ������������������������������ ������������������������������ ��������� 105 Adding CORS Configuration to the Spring Boot App ������������������������������ ������������������������������ ������ 107 Playing with the Application ������������������������������ ������������������������������ ������������������������������ ������������ 108 Deploying the React App ������������������������������ ������������������������������ ������������������������������ ����������������� 109 Summary and Achievements ������������������������������ ������������������������������ ������������������������������
������������������������������ ���������� 112 Chapter 5: The Data Layer ������������������������������ ������������������������������ ������������������������ 115 The Data Model ������������������������������ ������������������������������ ������������������������������ ������������������������������ � 117 Choosing a Database ������������������������������ ������������������������������ ������������������������������ ���������������������� 119 SQL vs� NoSQL ������������������������������ ������������������������������ ������������������������������ ��������������������������� 121 H2, Hibernate, and JPA ������������������������������ ������������������������������ ������������������������������ �������������� 122 Spring Boot Data JPA ������������������������������ ������������������������������ ������������������������������