100% found this document useful (5 votes)
108 views

Download Complete Learn Microservices with Spring Boot 3: A Practical Approach Using Event-Driven Architecture, Cloud-Native Patterns, and Containerization 3rd Edition Moisés Macero García PDF for All Chapters

Microservices

Uploaded by

yangsuwerts
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (5 votes)
108 views

Download Complete Learn Microservices with Spring Boot 3: A Practical Approach Using Event-Driven Architecture, Cloud-Native Patterns, and Containerization 3rd Edition Moisés Macero García PDF for All Chapters

Microservices

Uploaded by

yangsuwerts
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

Download Full Version ebookmass - Visit ebookmass.

com

Learn Microservices with Spring Boot 3: A


Practical Approach Using Event-Driven
Architecture, Cloud-Native Patterns, and
Containerization 3rd Edition Moisés Macero García
https://ebookmass.com/product/learn-microservices-with-
spring-boot-3-a-practical-approach-using-event-driven-
architecture-cloud-native-patterns-and-containerization-3rd-
edition-moises-macero-garcia/

OR CLICK HERE

DOWLOAD NOW

Discover More Ebook - Explore Now at ebookmass.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Learn Microservices with Spring Boot 3 3rd / converted


Edition Moises Macero Garcia

https://ebookmass.com/product/learn-microservices-with-spring-
boot-3-3rd-converted-edition-moises-macero-garcia/

ebookmass.com

Beginning Spring Boot 3: Build Dynamic Cloud-Native Java


Applications and Microservices - Second Edition K. Siva
Prasad Reddy
https://ebookmass.com/product/beginning-spring-boot-3-build-dynamic-
cloud-native-java-applications-and-microservices-second-edition-k-
siva-prasad-reddy/
ebookmass.com

Practical Spring Cloud Function: Developing Cloud-Native


Functions for Multi-Cloud and Hybrid-Cloud Environments
1st Edition Banu Parasuraman
https://ebookmass.com/product/practical-spring-cloud-function-
developing-cloud-native-functions-for-multi-cloud-and-hybrid-cloud-
environments-1st-edition-banu-parasuraman-2/
ebookmass.com

Tame My Life (Nasty Bastards MC Book 2) Hayley Faiman

https://ebookmass.com/product/tame-my-life-nasty-bastards-mc-
book-2-hayley-faiman/

ebookmass.com
Cunningham and Gilstrap’s Operative Obstetrics 3rd Edition
Edward R. Yeomans

https://ebookmass.com/product/cunningham-and-gilstraps-operative-
obstetrics-3rd-edition-edward-r-yeomans/

ebookmass.com

Cyber Threat Intelligence, 2023 Edition Martin Lee

https://ebookmass.com/product/cyber-threat-intelligence-2023-edition-
martin-lee/

ebookmass.com

Dysphagia E Book: Clinical Management in Adults and


Children 2nd Edition, (Ebook PDF)

https://ebookmass.com/product/dysphagia-e-book-clinical-management-in-
adults-and-children-2nd-edition-ebook-pdf/

ebookmass.com

Public Humanities and the Spanish Civil War: Connected and


Contested Histories 1st ed. Edition Alison Ribeiro De
Menezes
https://ebookmass.com/product/public-humanities-and-the-spanish-civil-
war-connected-and-contested-histories-1st-ed-edition-alison-ribeiro-
de-menezes/
ebookmass.com

I Promise It Won't Always Hurt Like This: 18 Assurances on


Grief Clare Mackintosh

https://ebookmass.com/product/i-promise-it-wont-always-hurt-like-
this-18-assurances-on-grief-clare-mackintosh/

ebookmass.com
The Last Flight: A Novel Julie Clark

https://ebookmass.com/product/the-last-flight-a-novel-julie-clark/

ebookmass.com
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
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���������������������������������������������������������������������������������������������������������������� 123
Dependencies and Autoconfiguration���������������������������������������������������������������������������������� 123
Spring Boot Data JPA Technology Stack������������������������������������������������������������������������������ 128
Data Source (Auto)configuration����������������������������������������������������������������������������������������� 130
Entities�������������������������������������������������������������������������������������������������������������������������������������� 132
Repositories������������������������������������������������������������������������������������������������������������������������������ 137
Storing Users and Attempts������������������������������������������������������������������������������������������������������ 141
Displaying Last Attempts���������������������������������������������������������������������������������������������������������� 147
Service Layer����������������������������������������������������������������������������������������������������������������������� 147

vii
Table of Contents

Controller Layer������������������������������������������������������������������������������������������������������������������� 149


User Interface���������������������������������������������������������������������������������������������������������������������� 155
Playing with the New Feature��������������������������������������������������������������������������������������������������� 163
Summary and Achievements���������������������������������������������������������������������������������������������������� 165

Chapter 6: Starting with Microservices���������������������������������������������������������������� 169


The Small Monolith Approach��������������������������������������������������������������������������������������������������� 170
Why a Small Monolith?������������������������������������������������������������������������������������������������������������� 170
The Problems with Microservices from Day Zero���������������������������������������������������������������� 170
Small Monoliths Are for Small Teams���������������������������������������������������������������������������������� 171
Embracing Refactoring�������������������������������������������������������������������������������������������������������� 172
Planning the Small Monolith for a Future Split������������������������������������������������������������������������� 173
New Requirements and Gamification��������������������������������������������������������������������������������������� 174
Gamification: Points, Badges, and Leaderboards���������������������������������������������������������������� 175
Moving to Microservices����������������������������������������������������������������������������������������������������������� 176
Independent Workflows������������������������������������������������������������������������������������������������������� 177
Horizontal vs. Vertical Scalability���������������������������������������������������������������������������������������� 178
Fine-Grained Nonfunctional Requirements������������������������������������������������������������������������� 180
Other Advantages���������������������������������������������������������������������������������������������������������������� 180
Disadvantages��������������������������������������������������������������������������������������������������������������������� 181
Architecture Overview�������������������������������������������������������������������������������������������������������������� 183
Designing and Implementing the New Service������������������������������������������������������������������������� 185
Interfaces���������������������������������������������������������������������������������������������������������������������������� 186
The Spring Boot Skeleton for Gamification������������������������������������������������������������������������� 186
Domain�������������������������������������������������������������������������������������������������������������������������������� 187
Service�������������������������������������������������������������������������������������������������������������������������������� 192
Data������������������������������������������������������������������������������������������������������������������������������������� 204
Controller����������������������������������������������������������������������������������������������������������������������������� 207
Configuration����������������������������������������������������������������������������������������������������������������������� 209
Changes in Multiplication Microservice������������������������������������������������������������������������������ 211
UI����������������������������������������������������������������������������������������������������������������������������������������� 216
Playing with the System����������������������������������������������������������������������������������������������������������� 222

viii
Table of Contents

Fault Tolerance�������������������������������������������������������������������������������������������������������������������������� 224


The Challenges Ahead��������������������������������������������������������������������������������������������������������������� 226
Tight Coupling���������������������������������������������������������������������������������������������������������������������� 227
Synchronous Interfaces vs. Eventual Consistency�������������������������������������������������������������� 227
Transactions������������������������������������������������������������������������������������������������������������������������ 232
API Exposure������������������������������������������������������������������������������������������������������������������������ 234
Summary and Achievements���������������������������������������������������������������������������������������������������� 234

Chapter 7: Event-Driven Architectures����������������������������������������������������������������� 237


Core Concepts��������������������������������������������������������������������������������������������������������������������������� 238
The Message Broker������������������������������������������������������������������������������������������������������������ 238
Events and Messages���������������������������������������������������������������������������������������������������������� 242
Thinking in Events��������������������������������������������������������������������������������������������������������������� 242
Asynchronous Messaging���������������������������������������������������������������������������������������������������� 248
Reactive Systems���������������������������������������������������������������������������������������������������������������� 251
Pros and Cons of Going Event-Driven��������������������������������������������������������������������������������������� 252
Messaging Patterns������������������������������������������������������������������������������������������������������������������ 255
Publish-Subscribe��������������������������������������������������������������������������������������������������������������� 256
Work Queues����������������������������������������������������������������������������������������������������������������������� 256
Filtering������������������������������������������������������������������������������������������������������������������������������� 256
Data Durability��������������������������������������������������������������������������������������������������������������������� 256
Message Broker Protocols, Standards, and Tools��������������������������������������������������������������������� 257
AMQP and RabbitMQ����������������������������������������������������������������������������������������������������������������� 259
Overall Description�������������������������������������������������������������������������������������������������������������� 259
Exchange Types and Routing����������������������������������������������������������������������������������������������� 260
Message Acknowledgments and Rejection������������������������������������������������������������������������� 263
Setting Up RabbitMQ����������������������������������������������������������������������������������������������������������������� 264
Spring AMQP and Spring Boot�������������������������������������������������������������������������������������������������� 266
Solution Design������������������������������������������������������������������������������������������������������������������������� 266
Adding the AMQP Starter����������������������������������������������������������������������������������������������������� 269
Event Publishing from Multiplication����������������������������������������������������������������������������������� 270
Gamification as a Subscriber���������������������������������������������������������������������������������������������� 277

ix
Table of Contents

Analysis of Scenarios���������������������������������������������������������������������������������������������������������������� 286


Happy Flow�������������������������������������������������������������������������������������������������������������������������� 288
Gamification Becomes Unavailable������������������������������������������������������������������������������������� 296
The Message Broker Becomes Unavailable������������������������������������������������������������������������ 298
Transactionality������������������������������������������������������������������������������������������������������������������� 300
Scaling Up Microservices���������������������������������������������������������������������������������������������������� 303
Summary and Achievements���������������������������������������������������������������������������������������������������� 309

Chapter 8: Common Patterns in Microservice Architectures������������������������������� 313


Gateway������������������������������������������������������������������������������������������������������������������������������������ 314
Spring Cloud Gateway��������������������������������������������������������������������������������������������������������� 316
The Gateway Microservice�������������������������������������������������������������������������������������������������� 321
Changes in Other Projects��������������������������������������������������������������������������������������������������� 326
Running the Gateway Microservice������������������������������������������������������������������������������������� 327
Next Steps��������������������������������������������������������������������������������������������������������������������������� 329
Health���������������������������������������������������������������������������������������������������������������������������������������� 330
Spring Boot Actuator����������������������������������������������������������������������������������������������������������� 331
Including Actuator in Your Microservices���������������������������������������������������������������������������� 334
Service Discovery and Load Balancing������������������������������������������������������������������������������������� 337
Consul���������������������������������������������������������������������������������������������������������������������������������� 343
Spring Cloud Consul������������������������������������������������������������������������������������������������������������ 345
Spring Cloud Load Balancer������������������������������������������������������������������������������������������������ 354
Service Discovery and Load Balancing in the Gateway������������������������������������������������������� 358
Playing with Service Discovery and Load Balancing����������������������������������������������������������� 362
Configuration per Environment������������������������������������������������������������������������������������������������� 372
Configuration in Consul������������������������������������������������������������������������������������������������������� 375
Spring Cloud Consul Config������������������������������������������������������������������������������������������������� 376
Implementing Centralized Configuration����������������������������������������������������������������������������� 378
Centralized Configuration in Practice���������������������������������������������������������������������������������� 382

x
Table of Contents

Centralized Logs����������������������������������������������������������������������������������������������������������������������� 389


Log Aggregation Pattern������������������������������������������������������������������������������������������������������ 389
A Simple Solution for Log Centralization����������������������������������������������������������������������������� 391
Consuming Logs and Printing Them������������������������������������������������������������������������������������ 395
Distributed Tracing�������������������������������������������������������������������������������������������������������������������� 402
Spring Cloud Sleuth������������������������������������������������������������������������������������������������������������� 403
Implementing Distributed Tracing��������������������������������������������������������������������������������������� 405
Containerization������������������������������������������������������������������������������������������������������������������������ 407
Docker��������������������������������������������������������������������������������������������������������������������������������� 410
Spring Boot and Buildpacks������������������������������������������������������������������������������������������������ 413
Running Your System in Docker������������������������������������������������������������������������������������������ 415
Dockerizing Microservices�������������������������������������������������������������������������������������������������� 417
Dockerizing the UI��������������������������������������������������������������������������������������������������������������� 417
Dockerizing the Configuration Importer������������������������������������������������������������������������������ 418
Docker Compose����������������������������������������������������������������������������������������������������������������� 421
Scaling Up the System with Docker������������������������������������������������������������������������������������ 435
Sharing Docker Images������������������������������������������������������������������������������������������������������� 438
Platforms and Cloud-Native Microservices������������������������������������������������������������������������������� 442
Container Platforms������������������������������������������������������������������������������������������������������������� 442
Application Platforms���������������������������������������������������������������������������������������������������������� 444
Cloud Providers������������������������������������������������������������������������������������������������������������������� 444
Making a Decision��������������������������������������������������������������������������������������������������������������� 446
Cloud-Native Microservices������������������������������������������������������������������������������������������������ 447
Conclusions������������������������������������������������������������������������������������������������������������������������������� 447

Index��������������������������������������������������������������������������������������������������������������������� 451

xi
About the Authors
Moisés Macero García has been a software developer since he was a kid, when he
started playing around with BASIC on his ZX Spectrum. During his career, Moisés has
most often worked in development and architecture for small and large projects, and
for his own startups as well. He enjoys making software problems simple, and he likes
working in teams, where he can coach others as well as learn from them. Moisés is the
author of the blog thepracticaldeveloper.com, where he shares solutions to technical
challenges, guides, and his view on different ways of working in IT companies. He
also organizes workshops for companies that need a practical approach to software
engineering. In his free time, he enjoys traveling and hiking.

Tarun Telang is a seasoned and hands-on technologist


with a wealth of experience in designing and implementing
highly scalable software applications. With an impressive
career spanning over 18 years, Tarun has been a valuable
contributor to renowned companies such as Microsoft,
Oracle, Polycom, and SAP. He began his career as an
enterprise Java developer at SAP, where he honed his skills
in crafting distributed business applications tailored for
large enterprises. Through his dedication to continuous
learning and professional development, he became an
Oracle Certified Java Programmer and SAP Certified Development Consultant for
Enterprise Java.
As a prolific author, Tarun frequently writes on Java and related technologies, and he
has authored many books and online courses. His earlier books Java EE to Jakarta EE 10
Recipes, and Beginning cloud-native development using MicroProfile, Jakarta EE and
Kubernetes have been well-received by the tech community. He has also been a sought-
after speaker at developer conferences like SAP TechEd and the Great Indian Developer
Summit, sharing his technical expertise with enthusiastic audiences. Tarun regularly
shares technological insights at www.practicaldeveloper.com.

xiii
About the Authors

Tarun’s expertise lies in architecting and developing large scale applications, with a
particular focus on cloud-­native solutions using cutting-edge architectural patterns like
microservices and event-driven architecture. He has led the development of numerous
end-to-end cloud-based solutions, demonstrating his deep technical understanding to
deliver high-performing, reliable, large-scale applications.
An advocate of agile methodologies, Tarun excels at applying domain-driven design
and behavioral-driven development principles, ensuring seamless project management
and collaboration across cross-functional teams in different geographical locations. His
international experience, having worked in India, Canada and Germany, has enriched
his global perspective and ability to adapt to diverse environments. Tarun lives in
Hyderabad, India, and he enjoys spending time with his wife and child when he’s not
indulging in his love of technology. You can follow Tarun or contact him on his Twitter
account: @taruntelang.

xiv
About the Technical Reviewer
Manuel Jordan Elera is an autodidactic developer and
researcher who enjoys learning new technologies for his
own experiments and creating new integrations. Manuel
won the Springy Award 2013 Community Champion and
Spring Champion. In his little free time, he reads the Bible
and composes music on his guitar. Manuel is known as
dr_pompeii. He has tech-reviewed numerous books,
including Pro Spring MVC with WebFlux (Apress, 2020),
Pro Spring Boot 2 (Apress, 2019), Rapid Java Persistence
and Microservices (Apress, 2019), Java Language Features
(Apress, 2018), Spring Boot 2 Recipes (Apress, 2018), and Java APIs, Extensions and
Libraries (Apress, 2018). You can read his detailed tutorials on Spring technologies and
contact him through his blog at www.manueljordanelera.blogspot.com. You can follow
Manuel on his Twitter account, @­ dr_pompeii.

xv
Acknowledgments
I would like to thank my wife, Nikita, and son, Vihan, for their patience
and love throughout the process of writing this book. I am indebted to all
my mentors and friends who always encouraged me to keep growing in
every phase of my professional career.
I’d like to thank my parents for pushing me in the right direction with tech-
nology and always supporting me every step of the way, even when I decided
to do something completely different than they expected. It’s also important
to note that without them, I probably wouldn’t have become a developer
and had such a great career. Lastly, thanks again go out to my wife (and
soulmate), Nikita. It’s an incredible feeling to be with someone who keeps
you motivated and challenges you, not only professionally but personally
as well.

Thank you for always being there for me!


I’d like to send a special thanks to Manuel Jordan (the technical reviewer),
for their impeccable work on this book. I also greatly appreciate Mark
Powers, and everyone at Apress Media (apress.com) for their support in
getting this book published.
Last, but not least, I would like to thank you, the reader, for taking the time
to read this book. We have tried our best through this book to offer you a
comprehensive, up-to-date, and practical guide that empowers you to build
sophisticated and resilient microservices architectures using Spring Boot.
—Tarun Telang

xvii
About this Book
Welcome to Learn Microservices with Spring Boot 3: A Practical Approach
Using an Event-Driven Architecture, Cloud-Native Patterns, and
Containerization.
In today’s fast-paced digital landscape, the demand for highly scalable,
flexible, and maintainable software solutions has reached new heights.
Microservices architecture has emerged as a game-changing paradigm,
empowering developers to build complex applications by breaking them
down into smaller, decoupled, and independently deployable services. At
the heart of this revolution lies Spring Boot, a robust and widely adopted
framework that simplifies the development and deployment of Java-based
microservices.

This book is your gateway to unlocking the potential of microservices with Spring
Boot 3. Whether you are an experienced developer looking to adopt modern
software architecture or a newcomer eager to explore the world of microservices, this
comprehensive guide will equip you with the knowledge and tools necessary to build
cutting-edge applications.

Your Path to Mastering Microservices


In this third edition, we have curated a rich learning journey that starts with the
fundamentals and gradually leads you to construct a fully functional microservices
ecosystem. We begin by introducing the core concepts of microservices architecture and
the advantages it offers over traditional monolithic systems. As you familiarize yourself
with the principles, we explore Spring Boot 3, the latest version of the framework,
compatible with Java 17 and Jakarta EE 10.

xix
About this Book

Building Your Microservices Ecosystem


Transitioning from a monolithic architecture to microservices can be a daunting
task. However, fear not, as this book provides a smooth and incremental approach
to guide you through the transformation process. You learn how to break down
your monolithic application into cohesive microservices, each dedicated to specific
business functionalities. Along the way, we delve into event-driven architecture, an
essential aspect of building scalable and resilient microservices, to enable seamless
communication and collaboration between services.

Data Layer, Containerization, and Orchestration


An essential part of microservices development lies in efficiently managing data and
ensuring seamless deployment and scalability. We explore Spring Boot’s capabilities
in accessing the Spring Data project and its APIs to handle data storage and retrieval
effectively. Containerization with Docker will become your ally as you learn to package
and deploy microservices efficiently.

Security, Monitoring, and Frontend Integration


A successful microservices ecosystem demands robust security measures and diligent
monitoring. We cover essential security practices to safeguard your microservices and
delve into monitoring their performance for seamless operation. Moreover, we explore
integrating frontend development with React.js, enabling you to create user-friendly user
interfaces that interact flawlessly with your microservices.

From Expert Insights to Real-World Use Cases


Throughout this book, you will benefit from the expertise of the authors—Tarun
Telang and Moisés Macero García—who have a wealth of knowledge in designing
and implementing scalable software applications. From their real-world insights to
practical examples, you’ll receive invaluable guidance to tackle the challenges of modern
application development head-on.

xx
About this Book

Begin Your Microservices Journey


Whether you are an aspiring developer or a seasoned pro, this book offers a
comprehensive and up-to-date guide to mastering microservices architecture. Embark
on this exciting journey to build scalable, resilient, and cloud-native applications that
meet the demands of today’s dynamic software landscape. Let’s dive in and unlock the
potential of microservices with Spring Boot 3!

What You Will Learn


• Gain a thorough understanding of microservices architecture,
including its principles and benefits, and how it differs from
monolithic architectures.

• Discover the step-by-step process of breaking down a monolithic


application into smaller, focused services, each responsible for
specific functionalities.

• Learn about TDD techniques and what their benefits are.

• Build microservices with Spring Boot 3, Spring Data, Spring Cloud,


Docker, Cucumber, and more.

• Learn to develop Java-based microservices with the latest version


of Spring Boot 3, Java 17, and Jakarta EE 10 using a three-tier, three-­
layer design.

• Use an event-driven architecture. Implement resilience and


scalability with RabbitMQ or Apache Kafka.
• Discover architecture patterns for distributed systems such
as asynchronous processing, eventual consistency, resilience,
scalability, and more.

• Keep flexible configurations per environment with Spring


Cloud Consul.

• Gain insights into event-driven communication patterns and learn


how to design and build event-driven microservices.

xxi
About this Book

• Master service discovery with Consul and load balancing with Spring
Cloud Load Balancer.

• Route requests with Spring Cloud Gateway.

• Trace every request from beginning to end with Sleuth and


centralized logging.

• Deploy your microservices anywhere as Docker containers.

• Adopt cloud-native practices to optimize your microservices


deployment on modern cloud platforms, enhancing scalability and
flexibility.

• Learn the essentials of containerization using Docker, allowing you to


package and deploy microservices efficiently.

• Start all the components in the microservice architecture with


Docker Compose.

• Learn how to achieve your non-functional requirements with


practical case studies for scalability, fault-tolerance, retries,
and so on.

• Deploy your microservices anywhere as Docker containers with


Buildpacks.

• As a side track, learn how to build simple frontend interfaces


with React.

In this book, the authors use a pragmatic approach to explain the benefits of using
this type of software architecture, instead of distracting you with theoretical concepts.
They cover some of the state-of-the-art techniques in computer programming, from
a practical point of view. The emphasis is on what matters most—starting with the
minimum viable product but maintaining the ability to adapt and improve over time.

xxii
About this Book

Downloading the Code


The code for the examples shown in this book is available at ­https://github.com/
Book-Microservices-­v3.

Note The sources for this book may change over time, to provide new
implementations that incorporate the most up-to-date features in Spring Boot.
That said, if any issues are found in the sources, please submit them via the book’s
GitHub repo, and the code will be adjusted accordingly.

xxiii
CHAPTER 1

Setting the Scene


A microservices architecture allows you to design software systems as a collection of
independent services that communicate through APIs. Each microservice performs
a specific business function and is responsible for its data storage, processing, and
delivery.
Microservices have become the de facto standard for building complex and scalable
systems. This is not surprising, given the numerous benefits of this software architecture
style. Microservices offer increased scalability, flexibility, and resilience, as well as
the ability to develop and deploy services independently. Additionally, microservices
provide the potential for easier maintenance and updates compared to other
architecture styles. Mapping microservices into small teams in an organization also gives
you a lot of efficiency in development. However, going on the adventure of microservices
while knowing only the benefits is the wrong approach.
The microservices approach also leads to the distribution of the system’s
functionality across multiple microservices, each running independently and
communicating with others through a network. As a result, the overall system becomes
distributed, consisting of numerous smaller, independent services that work together
to deliver the desired functionality. This architecture style allows for greater flexibility,
scalability, and resilience, but it also introduces additional complexity, which you need
to manage carefully. You can get a lot of knowledge from many books and articles on the
Internet, but when you get hands-on with the code, the story changes.
This book covers some of the essential concepts of microservices practically, but
only by explaining those concepts. In this book, you build an application where users
can exercise their brains by performing mathematical calculations. Users will be
presented with a new problem every time they access the application. They provide their
alias (a short name) and submit answers to the problem. After they submit their input,
the web page will indicate whether their answer is correct.

1
© Moisés Macero García and Tarun Telang 2023
M. Macero García and T. Telang, Learn Microservices with Spring Boot 3,
https://doi.org/10.1007/978-1-4842-9757-5_1
Chapter 1 Setting the Scene

First, you define a use case: an application to build. Then you start with a small
monolith based on some sound reasoning. Once you have the minimal application in
place, you evaluate whether it’s worth moving to microservices and learn how to do that
well, including building RESTful APIs, adding security features, and scaling services.
The book also introduces essential microservices design principles, such as the single
responsibility principle, loose coupling, service autonomy, and bounded contexts from
domain-driven design. With the introduction of the second microservice, we analyze the
options you have for their communication. Then, you can describe and implement the
event-driven architecture pattern to reach loose coupling by informing other parts of the
system about what happened, instead of explicitly calling others to action. Event-driven
architecture is a powerful pattern for designing reactive and resilient microservices.
You will also explore commonly used communication patterns that facilitate
seamless coordination and collaboration between microservices. These patterns can
be classified into two categories—synchronous communication and asynchronous
communication.
For synchronous communication, you will study patterns such as request-response,
message broker, API gateway, choreography, and orchestration. These patterns enable
real-time interactions between services, ensuring that requests and responses are
handled in a coordinated manner.
On the other hand, for asynchronous communication, you will delve into event
sourcing and publish-subscribe patterns. These patterns allow services to communicate
asynchronously by leveraging events and messages, promoting loose coupling and
enabling independent processing.
By examining these communication patterns, you’ll gain a comprehensive
understanding of how microservices can effectively interact and work together, both
in synchronous and asynchronous scenarios. This knowledge empowers you to
design robust and efficient communication mechanisms within your microservices
architecture.
When you reach that point, you’ll notice that a poorly designed distributed system
has some flaws that you must fix with popular patterns: service discovery, routing, load
balancing, traceability, and more.
You will also explore the circuit breaker pattern as another important
communication pattern for microservices. The circuit breaker pattern acts as a safeguard
against cascading failures and helps manage the resilience of communication between
services.

2
Chapter 1 Setting the Scene

By studying the circuit breaker pattern, you will understand how it detects failures
in remote service calls and provides a fail-fast mechanism. It helps prevent further calls
to a failing service, thus reducing the impact of failures on the overall system. The circuit
breaker pattern also includes mechanisms for monitoring the health of services and
adapting to changing conditions.
Incorporating the circuit breaker pattern into your communication strategies
ensures that your microservices ecosystem remains stable, resilient, and responsive,
even in the face of potential failures or degradation in service performance.
Adding them individually to your codebase instead of presenting all of them together
helps you understand these patterns. You can also prepare these microservices for
cloud deployment by understanding cloud-native architectures and containerization,
learning about cloud-native architectures and containerization, using Docker for
containerization and Kubernetes for orchestration, and comparing the different platform
alternatives to run the applications. By following these steps, you can gain a practical
understanding of microservices and learn how to design, implement, and deploy
microservices-based systems.
Throughout this book you will build microservices from scratch using Spring
Boot. The advantage of going step-by-step, pausing when needed to nail down the
concepts, is that you will understand which problem each tool is trying to solve. That’s
why the evolving example is an essential part of this book. You can also grasp the
concepts without coding a single line since the source code is presented and explained
throughout the chapters.
All the code included in this book is available on GitHub in the organization
Book-Microservices-v3. Multiple repositories are available and divided into chapters
and sections, making it easier to see how the application evolves. The book includes
notes with the version covered in each part. By following these steps, you can gain a
practical understanding of microservices and learn how to design, implement, and
deploy microservices-based systems.

Who Are You?


Let’s start with this: how interesting will this book be to you? This book is practical, so
let’s play this game. If you identify with any of these statements, this book might be good
for you:

3
Chapter 1 Setting the Scene

• “I would like to learn how to build microservices with Spring Boot


and how to use the related tools.”

• “Everybody is talking about microservices, but I have no clue what


a microservice is yet. I have read only theoretical explanations or
just hype-enforcing articles. I can’t understand the advantages, even
though I work in IT….”

• “I would like to learn how to design and develop Spring Boot


applications, but all I find are either quick-start guides with too
simple examples or lengthy books that resemble the official
documentation. I would like to learn the concepts following a more
realistic, project-guided approach.”

• “I got a new job, and they’re using a microservices architecture. I’ve


been working mainly in big, monolithic projects, so I’d like to have
some knowledge and guidance to learn how everything works there,
as well as the pros and cons of this architecture.”

• “Every time I go to the cafeteria, developers talk about microservices,


gateways, service discovery, containers, resilience patterns, and so
on. I can’t socialize anymore with my colleagues if I don’t get what
they’re saying.” (This one is a joke; don’t read this book because of
that, especially if you’re not interested in programming.)

Regarding the knowledge required to read this book, the following topics should be
familiar to you:

• Java (we use Java 17)

• Spring (you don’t need strong experience, but you should know at
least how dependency injection works)

• Maven (if you know Gradle, you’ll be fine as well)

4
Chapter 1 Setting the Scene

 ow Is This Book Different from Other Books


H
and Guides?
Software developers and architects read many technical books and guides because
they’re interested in learning new technologies, or their work requires it. They need to
do that anyway since it’s a constantly changing world. You can find all kinds of books and
guides out there. You can learn quickly from the good ones, which teach you not only
how to do stuff but also explain why you should do it that way.
Using the latest techniques just because they’re new is the wrong way to go about
it; you need to understand the reasoning behind them, so you use them in the best way
possible.
This book uses that philosophy: it navigates through the code and design patterns,
explaining the reasons to follow one way and not others.

Learning: An Incremental Process


If you look at the guides available on the Internet, you’ll quickly notice that they are not
real-life examples. Usually, when you apply those cases to more complex scenarios,
they don’t fit. Guides need to be deeper to help you build something real. Books, on the
other hand, are much better at that. Plenty of good books explain concepts around an
example; they are good because applying theoretical concepts to code is only sometimes
possible if you don’t see the code. The problem with some of these books is that they’re
less practical than guides. It helps when you read them first to understand the concepts
and then code (or see) the example, which we have frequently given as a whole piece.
It isn’t easy to put concepts into practice when you view the final version directly. This
book stays practical and starts with code. It evolves through the chapters so that you
grasp the ideas one by one. We cover the problem before exposing the solution.
Because of this incremental way of presenting concepts, this book also allows you to
code as you learn and to reflect on the challenges by yourself.

Is This a Guide or a Book?


The pages you have in front of you can’t be called a guide: it will take you 15 or 30
minutes to finish them. Besides, each chapter introduces all the required topics to lay the
foundation for the new code additions. But this is not the typical book either, in which

5
Chapter 1 Setting the Scene

you go through isolated concepts, illustrated with scattered code fragments explicitly
made for that situation. Instead, you start with a real-life application that is yet to be
optimal, and you learn how to evolve it after learning about the benefits you can extract
from that process.
That does not mean you can’t just sit down and read it, but it’s better if your code
simultaneously plays with the options and alternatives presented. That’s part of the book
that makes it like a guide. To keep it simple, we call this a book from here onward.

From Basics to Advanced Topics


This book focuses on some essential concepts that build on the rest of the topics
(Chapter 2)—Spring Boot, testing, logging, and so on. Then, it covers how to design and
implement a production-ready Spring Boot application using a well-known layered
design. It dives into how to implement a REST API, business logic, and database
repositories (Chapters 3 and 5). While doing that, you see how Spring Boot works
internally, so it’s not magic to you anymore. You also learn how to build a basic frontend
application with React (Chapter 4) because that will help you visualize how the backend
architecture impacts the frontend. After that, the book enters the microservices world by
introducing a second piece of functionality in a different Spring Boot app. The practical
example helps you analyze the factors you should examine before deciding to move to
microservices (Chapter 6). Then, you learn the differences between communicating
microservices synchronously and asynchronously and how an event-driven architecture
can help you keep your system components decoupled (Chapter 7). From there, the
book takes you through the journey of tools and frameworks applicable to distributed
systems to achieve necessary nonfunctional requirements: resilience, scalability,
traceability, and deployment to the cloud, among others (Chapter 8).
If you are already familiar with Spring Boot applications and how they work, you
can go quickly through the first chapters and focus more on the second part of the
book. More advanced topics are covered in the second part, including event-driven
design, service discovery, routing, distributed tracing, testing with Cucumber, and
so on. However, pay attention to the foundations set up in the first part: test-driven
development, the focus on the minimum viable product (MVP), and monolith-first.

6
Chapter 1 Setting the Scene

Skeleton with Spring Boot, the Professional Way


First, the book guides you through creating an application using Spring Boot. The
contents mainly focus on the backend side, but you will create a simple web page with
React to demonstrate how to use the exposed functionality as a REST API.
It’s important to point out that you don’t create “shortcut code” to showcase Spring
Boot features: that’s not the objective of this book. It uses Spring Boot as a vehicle to
teach concepts, but you could use any other framework, and the ideas of this book would
still be valid.
You learn how to design and implement the application following the well-known
three-tier, three-layer pattern. You do this supported by an incremental example with
hands-on code. While writing the applications, you’ll pause a few times to get into the
details about how Spring Boot works with so little code (autoconfiguration, starters, etc.).

Test-Driven Development
In the first chapters, you use test-driven development (TDD) to map the prerequisites
presented to technical features. This book tries to show this technique so you can see
the benefits from the beginning: why it’s always a good idea to think about the test cases
before writing your code. JUnit 5, AssertJ, and Mockito will serve you to build useful tests
efficiently.
The plan is the following: you’ll learn how to create the tests first, then make them
fail, and finally implement the logic to make them work.

Microservices
Once you have your first application ready, we introduce a second one that will interact
with the existing functionality. From that moment on, you’ll have a microservices
architecture. It doesn’t make any sense to try to understand the advantages of
microservices if you have only one of them. The real-life scenarios are always distributed
systems with functionality split into different services. As usual, to keep it practical, you’ll
analyze the specific situation for your case study, so you’ll see if moving to microservices
fits your needs.

7
Chapter 1 Setting the Scene

The book covers not only the reasons to split the system but also the disadvantages
that come with that choice. Once you make the decision to move to microservices, you’ll
learn which patterns you should use to build a good architecture for the distributed
system: service discovery, routing, load balancing, distributed tracing, containerization,
and some other supporting mechanisms.

Event-Driven Systems
An additional concept that does not always need to come with microservices is the event-­
driven architecture. This book uses it since it’s a pattern that fits well into a microservice
architecture, and you’ll make your choice based on good examples. You learn about the
differences between synchronous and asynchronous communication, as well as their
main pros and cons.
This asynchronous way of thinking introduces new ways of designing code, with
eventual consistency as one of the key changes to embrace. You’ll look at it while coding
your project, using RabbitMQ or Apache Kafka to send and receive messages between
microservices. Both of these messaging systems allow for distributed and decoupled
processing within your architecture.

Nonfunctional Requirements
When you build an application in the real world, you must take into account some
requirements that are not directly related to functionalities, but that prepare your system
to be more robust, to keep working in the event of failures, or to ensure data integrity.
Many of these nonfunctional requirements are related to things that can go wrong
with your software: network failures that make part of your system unreachable, a high
traffic volume that collapses your backend capacity, external services that don’t respond,
and so on.
In this book, you learn how to implement and verify patterns to make the system
more resilient and scalable. In addition, it discusses the importance of data integrity and
the tools that help you guarantee it.
The good part about learning how to design and solve all these nonfunctional
requirements is that it’s knowledge applicable to any system, no matter the
programming language and frameworks you’re using.

8
Chapter 1 Setting the Scene

Online Content
For this second edition of the book, we decided to create an online space where you can
keep learning new topics related to microservice architectures. On this web page, you’ll
find new guides that extend the practical use case covering other important aspects
of distributed systems. Additionally, new versions of the repositories using up-to-date
dependencies are published there.
The first guide that you’ll find online is about testing a distributed system with
Cucumber (https://cucumber.io/). This framework helps you build human-readable
test scripts to make sure your functionalities work end-to-end.
Visit https://github.com/Book-Microservices-v3/book-extras for all the extra
content and new updates about the book.

Summary
This chapter introduced the main goals of this book: to teach you the main aspects of a
microservice architecture by starting simple and then growing your knowledge through
the development of a sample project.
We also briefly covered the main content of the book: from monolith-first to
microservices with Spring Boot, test-driven development, event-driven systems,
common architecture patterns, nonfunctional requirements, and end-to-end testing
with Cucumber (online).
The next chapter starts with the first step of your learning path: a review of some
basic concepts.

9
CHAPTER 2

Basic Concepts
This book follows a practical approach, so most of the tools covered are introduced as
you need them. However, we’ll go over some core concepts separately because they’re
either the foundations of the evolving example or used extensively in the code examples,
namely, Spring, Spring Boot, testing libraries, Lombok, and logging. These concepts
deserve a separate introduction to avoid long interruptions in your learning path, which
is why this chapter includes an overview of them.
Remember that these sections intend to provide a sound knowledge base of these
frameworks and libraries. The primary objective of this chapter is to refresh the concepts
in your mind (if you already learned them) or grasp the basics so that you don’t need to
consult external references before reading the rest of the chapters.

Spring
The Spring Framework (https://spring.io/projects/spring-framework) is a popular
open-source application development framework consisting of a collection of libraries
and tools that provide a comprehensive programming and configuration model for
developing enterprise-level Java applications. It offers a wide range of features and
modules—such as dependency injection, aspect-oriented programming, data access,
transaction management, validation, internationalization, web development, and
more—that can be used individually or in combination to develop robust and scalable
applications. It is widely used by developers and organizations worldwide, and it has
become a standard for building complex Java-based applications. At the time of writing
the book, the latest version of the Spring framework is 6.0.9.
The Spring Framework primarily supports the Java programming language. However,
it also provides support for other JVM-based programming languages such as Groovy
and Kotlin.

11
© Moisés Macero García and Tarun Telang 2023
M. Macero García and T. Telang, Learn Microservices with Spring Boot 3,
https://doi.org/10.1007/978-1-4842-9757-5_2
Chapter 2 Basic Concepts

Spring Framework is popular for several reasons:

1. Modular and flexible: Spring Framework is highly modular and


provides a wide range of features that can be used individually or
in combination. It allows developers to use only the modules they
need, making it flexible and lightweight.

2. Dependency injection (DI): Spring Framework supports


powerful and flexible dependency injection, allowing developers
to easily manage dependencies between components of an
application, thus reducing code coupling and improving
maintainability.

3. Aspect-Oriented Programming (AOP): Spring AOP provides


a way to add cross-­cutting concerns to an application, such as
logging, caching, and security, without having to modify the core
application logic.

4. Data access: Spring provides several modules for database access


and object-­relational mapping, including Spring Data JDBC
(https://spring.io/projects/spring-data-jdbc) and Spring
Data JPA.

5. Transaction management: Spring provides a powerful


transaction management framework, which supports both
declarative and programmatic transaction management.

6. Web applications: Spring provides robust support for building


web applications. The Spring framework offers various features
and modules that facilitate the development of web-based
solutions with ease and efficiency. At the heart of web application
development with Spring lies Spring MVC (Model-View-
Controller). Spring MVC is a powerful framework that follows the
MVC architectural pattern, enabling developers to build scalable
and maintainable web applications. It provides a structured
approach to handling HTTP requests and mapping them to
appropriate controllers, processing business logic, and rendering
views for the user.

12
Chapter 2 Basic Concepts

7. Security: Spring Security (https://spring.io/projects/


spring-security) provides a comprehensive security framework,
which supports authentication, authorization, and other security-
related features.

8. Large community and documentation: Spring Framework


has a large and active community of developers and users, who
continuously contribute to the development and improvement
of the framework, provide support, and share knowledge and
resources.

9. Integration with other frameworks and libraries: Spring


Framework provides seamless integration with other technologies
and frameworks, such as Hibernate, JPA, REST, and more, making
it easier to develop and deploy applications.

10. Testability: Spring Framework makes it easier to write unit and


integration tests, which helps ensure the quality and reliability of
the application.

Spring provides lots of built-in implementations for many aspects of software


development, such as the following:

• Spring Data (https://spring.io/projects/spring-data) simplifies


data access for relational and NoSQL databases. It provides
support for several popular data access technologies, such as
JDBC, Hibernate, JPA, and MongoDB. It makes it easy to work with
databases and perform CRUD (Create, Read, Update and Delete)
operations.

• Spring Batch (https://spring.io/projects/spring-batch) is


a framework for building batch processing applications. It is a
lightweight, comprehensive framework that provides developers with
the tools to create batch jobs that can process large amounts of data
efficiently and reliably.
• Spring Security (https://spring.io/projects/spring-security) is
a security framework that abstracts security features to applications.

13
Chapter 2 Basic Concepts

• Spring Cloud (https://spring.io/projects/spring-cloud)


provides tools for developers to quickly build some of the common
patterns in distributed systems.

• Spring Integration (https://spring.io/projects/spring-


integration)is an implementation of enterprise integration patterns.
It facilitates integration with other enterprise applications using
lightweight messaging and declarative adapters.

• Spring MVC is a web framework for building Java web applications


based on the Model-View-Controller design pattern. It provides
a flexible and powerful platform for developing scalable and
maintainable web applications.

• Spring Web Flow (https://spring.io/projects/spring-webflow)


provides a powerful and comprehensive solution for managing
complex flows in web applications. It simplifies the development
process by abstracting away the low-level details of flow control and
state management, allowing developers to focus on creating intuitive
and efficient user experiences.

• Spring WebFlux is a reactive web framework for building non-­


blocking and event-driven applications on the JVM. It provides an
alternative to Spring MVC and supports asynchronous and non-­
blocking API for handling HTTP requests and responses using
reactive programming principles.

These built-in implementations make it easier for developers to build robust,


scalable, and maintainable applications, while reducing the amount of boilerplate code
that needs to be written.
As you can see, Spring is divided into different modules. All the modules are built
on top of the core Spring Framework, which establishes a common programming and
configuration model for software applications. This model itself is another important
reason to choose the framework since it facilitates good programming techniques such
as the use of interfaces instead of classes to decouple application layers via dependency
injection.

14
Chapter 2 Basic Concepts

A key topic in Spring is the Inversion of Control (IoC) container, which is supported
by the ApplicationContext interface (https://docs.spring.io/spring-framework/
docs/current/javadoc-api/org/springframework/context/ApplicationContext.
html). The ApplicationContext interface is a key component of the Spring Framework
that provides a powerful and flexible mechanism for managing object dependencies and
resources in an application. The IoC container creates this “space” in your application
where you, and the framework itself, can put some object instances such as database
connection pools, HTTP clients, and so on. These objects, called beans, can be later used
in other parts of your application, commonly through their public interface to abstract
your code from specific implementations. The mechanism to reference one of these
beans from the application context in other classes is called dependency injection, and in
Spring this is possible via various techniques like XML, YAML, Java-based annotations,
and JavaConfig. This provides a high degree of flexibility in how the application is
structured.
With XML configuration, you can define the various components of your web
application, such as controllers, views, and dependencies, in XML files. These files
typically have a suffix like .xml and follow a defined structure based on the Spring
framework’s XML schema.
Spring also supports configuration using YAML (YAML Ain’t Markup Language).
YAML is a human-readable data serialization format that is often used for configuration
files in various applications, including Spring. With YAML configuration, you can define
your Spring beans, properties, and other configuration elements in a structured and
easy-to-read format. YAML provides a more concise and visually appealing alternative
to XML for configuration purposes. To use YAML configuration in Spring, you typically
create a YAML file (with a .yml or .yaml extension) and define your configuration
elements using indentation and key-value pairs. For example, you can define beans,
their properties, and their dependencies in a hierarchical structure within the YAML
file. Spring Boot offers built-in support for YAML-based configuration files. Spring Boot
automatically loads and parses YAML files to configure the application at startup.
With YAML configuration, you can define your Spring beans, properties, and other
configuration elements in a structured and an easy-to-read format. YAML provides a
more concise and visually appealing alternative to XML for configuration purposes.
Spring also offers the option to configure web applications using annotations,
leveraging the power and simplicity of Java code. Annotations provide a more concise
and intuitive way to define the components and their configurations.

15
Chapter 2 Basic Concepts

Spring also offers the option to configure web applications using annotations,
leveraging the power and simplicity of Java code. Annotations provide a more concise
and intuitive way to define the components and their configurations.
By using annotations, you can mark your classes, methods, or fields with specific
annotations provided by Spring. For example, you can annotate a class with @Controller
to indicate it as a Spring MVC controller, use @RequestMapping to specify request
mappings, and use @Autowired to inject dependencies.
Using annotations reduces the need for YAML or XML configuration files, as the
configuration can be directly embedded in the source code. This approach promotes
better code readability, simplifies configuration management, and reduces the overall
configuration overhead.
Yet another Java-based configuration approach, known as “JavaConfig,” has
also gained significant popularity. It allows developers to define their application’s
configuration using plain Java classes annotated with Spring annotations. This provides
a more programmatic and type-safe way of configuring Spring components.
You see all these configuration options in action as you work through the sample
application.

Spring Boot
Spring Boot (https://spring.io/projects/spring-boot) is a framework that leverages
Spring to quickly create stand-alone applications in Java-based languages. It has become
a popular tool for building microservices.
Having so many available modules in Spring and other related third-party libraries
that can be combined with the framework is powerful for software development. Yet,
despite a lot of efforts to make Spring configuration easier, you still need to spend
some time to set up everything you need for your application. And, sometimes, you
just require the same configuration over and over again. Bootstrapping an application,
meaning the process to configure your Spring application to have it up and running,
is sometimes tedious. The advantage of Spring Boot is that it eliminates most of that
process by providing default configurations and tools that are set up automatically for
you. The main disadvantage is that if you rely too much on these defaults, you may
lose control and awareness of what’s happening. We unveil some of the Spring Boot
implementations in the book to demonstrate how it works internally so that you can
always be in control.

16
Chapter 2 Basic Concepts

Spring Boot provides some predefined starter packages that are like collections
of Spring modules and some third-party libraries and tools together. As an example,
spring-boot-starter-web helps you build a stand-alone web application. It groups
the Spring Core Web libraries with Jackson (JSON handling), validation, logging,
autoconfiguration, and even an embedded Tomcat server, among other tools. Other
starters include spring-boot-starter-data-jpa, which includes dependencies for
Spring Data JPA, Hibernate, and a database driver, and spring-boot-starter-test,
which includes dependencies for testing Spring Boot applications.
In addition to starters, autoconfiguration plays a key role in Spring Boot. This feature
makes adding functionality to your application extremely easy. It also helps ensure
that the application follows best practices and recommended design patterns, as the
autoconfiguration logic is based on well-established Spring patterns and practices.
Following the same example, just by including the web starter, you get an embedded
Tomcat server. There’s no need to configure anything. This is because the Spring Boot
auto configuration classes scan your classpath, properties, components, and so on, and
load some extra beans and behavior based on that.
To be able to manage different configuration options for your Spring Boot
application, the framework introduces profiles. You can use profiles, for example, to
set different values for the host to connect to when using a database in a development
environment and a production environment. Additionally, you can use a different profile
for tests, where you may need to expose additional functions or mock parts of your
application. We cover profiles more in detail in Chapter 8.
You’ll use the Spring Boot Web and Data starters to quickly build a web application
with persistent storage. The Test starter will help you write tests, given that it includes
some useful test libraries such as JUnit 5 (https://junit.org/junit5/) and AssertJ
(https://assertj.github.io/doc/). Then, you’ll see how to add messaging capabilities
to your applications by adding the AMQP starter, which includes a message broker
integration (RabbitMQ) that you’ll use to implement an event-driven architecture.
Chapter 8 includes a different type of starters, grouped within the Spring Cloud family.
You’ll use some of these tools to implement common patterns for distributed systems:
routing with Spring Cloud Gateway (https://cloud.spring.io), service discovery
with Consul (https://www.consul.io/), and load balancing with Spring Cloud Load
Balancer (https://spring.io/guides/gs/spring-cloud-loadbalancer/), among
others. Don’t worry about all these new terms for now; they’ll be explained in detail
while you make progress on the practical example.

17
Chapter 2 Basic Concepts

The next chapter covers in detail how these starters and Spring Boot
autoconfiguration work, based on a practical example.

Lombok and Java


The code examples in this book use Project Lombok (https://projectlombok.org/), a
library that generates Java code based on annotations. The current version of Lombok
at the time of writing this book was 1.18.28. The main reason to include Lombok in the
book is educational: it keeps the code samples concise, reducing the boilerplate so you
can focus on what it matters.
Let’s use one of the first simple classes as an example. Say you want to create an
immutable multiplication challenge class with two factors. See Listing 2-1.

Listing 2-1. The Challenge Class in Plain Java

/**
* Represents a challenge with two factors.
*/
public final class Challenge {
    // Both factors
    private final int factorA;
    private final int factorB;
    public Challenge(int factorA, int factorB) {
        this.factorA = factorA;
        this.factorB = factorB;
    }
    public int getFactorA() {
        return this.factorA;
    }
    public int getFactorB() {
        return this.factorB;
    }
   @Override
    public boolean equals(final Object o) {
        if (o == this) return true;
        if (!(o instanceof Challenge)) return false;

18
Chapter 2 Basic Concepts

        final Challenge other = (Challenge) o;


        if (this.getFactorA() != other.getFactorA()) return false;
        if (this.getFactorB() != other.getFactorB()) return false;
        return true;
    }
    @Override
    public int hashCode() {
        final int PRIME = 59;
        int result = 1;
        result = result * PRIME + factorA;
        result = result * PRIME + factorB;
        return result;
    }
    @Override
    public String toString() {
        return "Challenge [factorA=" + factorA + ", factorB=" +
factorB + "]";
    }
}

As you can see, the full class has some classic boilerplate code: constructors, getters,
and the equals, hashCode, and toString methods. They don’t add much to this book,
yet you need them for the code to work.
The same class can be reduced with Lombok to its minimum expression. See
Listing 2-2.

Listing 2-2. The Challenge Class Using Lombok

import lombok.Value;
@Value
public class Challenge {
    // Both factors
    int factorA;
    int factorB;
}

19
Chapter 2 Basic Concepts

The @Value annotation provided by Lombok groups some other annotations in this
library that you can also use separately. Each of the following annotations instructs
Lombok to generate code blocks before the Java build phase:

• @AllArgsConstructor creates a constructor with all the


existing fields.

• @FieldDefaults makes your fields private and final.

• @Getter generates getters for factorA and factorB.

• @ToString includes a simple implementation of concatenating fields.

• @EqualsAndHashCode generates basic equals() and hashCode()


methods using all fields by default, but you can also customize it.

Not only does Lombok reduce the code to the minimum, but it also helps when
you need to modify these classes. Adding a new field to the Challenge class in Lombok
means adding one line (excluding usages of the class). If you would use the plain Java
version, you would need to add the new argument to the constructor, add the equals
and hashCode methods, and add a new getter. Not only does that mean extra work, but
it’s also error-prone: if you forgot the extra field in the equals method, for example, you
would introduce a bug into your application.
Like many tools, Lombok also has detractors. The main reason not to like Lombok
is that, since it’s easy to add code to your classes, you might end up adding code that
you don’t really need (e.g., setters or extra constructors). Besides, you could argue that
having a good IDE with code generation and a refactoring assistant can help more or less
at the same level.
The coming chapters mainly use these Lombok features:

• We annotate with @Value the immutable classes.

• For the data entities, we use separately some of the annotations


described earlier.

• We add the @Slf4j annotation for Lombok to create a logger using


the standard Simple Logging Facade for Java API (SLF4J). SLF4J
(https://www.slf4j.org/) is a logging facade or abstraction layer
that provides a common logging API for various logging frameworks
in the Java ecosystem. It allows developers to write code that uses

20
Chapter 2 Basic Concepts

a single API for logging while being able to use different logging
frameworks under the hood. The section entitled “Logging” in this
chapter gives more background about these concepts.

In any case, you learn what these annotations do when you look at the code
examples, so you don’t need to dive into more details on how they work.
If you prefer plain Java code, just use the Lombok’s code annotations in this book as
a reference to know what extra code you need to include in your classes.

Java Records Starting with JDK 14, the Java records feature was introduced in
preview mode and became a standard feature in JDK 16. If you use this feature,
you could write the Challenge class in pure Java in a concise way as well.
public record Challenge(int factorA, int factorB) {}

Testing Basics
In this section, we go through some important testing approaches and libraries. We
put them into practice in the next chapters, so it’s good to learn (or review) the basic
concepts first.

Test-Driven Development
The first practical chapters in this book encourage you to use test-driven development
(TDD). TDD is a software development practice that involves writing automated tests
before writing the actual code. The idea behind TDD is to write small, incremental tests
that verify the functionality of the code at each step of development. This technique
helps you by putting the focus first on what you need and what your expectations are
and later move to the implementation. It makes you, as a developer, think about what
the code should do under certain situations or use cases. In real life, TDD also helps
you clarify vague requirements and discard invalid ones. TDD has become increasingly
popular in recent years, and it is widely used in agile software development.
Given that this book is driven by a practical case, you’ll find that TDD fits quite well
within the main purpose.

21
Random documents with unrelated
content Scribd suggests to you:
A Commercial Geography of the British Empire. By L. W.
Lyde, M.A. Fifth Edition. 2s.
A Commercial Geography of Foreign Nations. By F. C.
Boon, B.A. 2s.
A Primer of Business. By S. Jackson, M.A. Third Edition. 1s.
6d.
Commercial Arithmetic. By F. G. Taylor, M.A. Fourth
Edition. 1s. 6d.
French Commercial Correspondence. By S. E. Bally. With
Vocabulary. Third Edition. 2s.
German Commercial Correspondence. By S. E. Bally. With
Vocabulary. Second Edition. 2s. 6d.
A French Commercial Reader. By S. E. Bally. With
Vocabulary. Second Edition. 2s.
Precis Writing and Office Correspondence. By E. E.
Whitfield, M.A. Second Edition. 2s.
A Guide to Professions and Business. By H. Jones. 1s. 6d.
The Principles of Book-keeping by Double Entry. By J. E.
B. M‘Allen, M.A. 2s.
Commercial Law. By W. Douglas Edwards. Second Edition.
2s.

Connoisseur’s Library, The


Wide Royal 8vo. 25s. net.
A sumptuous series of 20 books on art, written by experts for
collectors, superbly illustrated in photogravure, collotype, and
colour. The technical side of the art is duly treated. The first
volumes are—
Mezzotints. By Cyril Davenport. With 40 Plates in
Photogravure.
Porcelain. By Edward Dillon. With 19 Plates in Colour, 20 in
Collotype, and 5 in Photogravure.
Miniatures. By Dudley Heath. With 9 Plates in Colour, 15 in
Collotype, and 15 in Photogravure.
Ivories. By A. Maskell. With 80 Plates in Collotype and
Photogravure.
English Furniture. By F. S. Robinson. With 160 Plates in
Collotype and one in Photogravure. Second Edition.
European Enamels. By H. Cunynghame, C.B. With many
Plates in Collotype and a Frontispiece in Photogravure.

Devotion, The Library of


With Introductions and (where necessary) Notes.

Small Pott 8vo, cloth, 2s.; leather, 2s. 6d. net.


These masterpieces of devotional literature are furnished
with such Introductions and Notes as may be necessary to
explain the standpoint of the author and the obvious difficulties
of the text, without unnecessary intrusion between the author
and the devout mind.
The Confessions of St. Augustine. Edited by C. Bigg, D.D.
Fifth Edition.
The Christian Year. Edited by Walter Lock, D.D. Third
Edition.
The Imitation of Christ. Edited by C. Bigg, D.D. Fourth
Edition.
A Book of Devotions. Edited by J. W. Stanbridge, B.D.
Second Edition.
Lyra Innocentium. Edited by Walter Lock, D.D.
A Serious Call to a Devout and Holy Life. Edited by C.
Bigg, D.D. Second Edition.
The Temple. Edited by E. C. S. Gibson, D.D. Second Edition.
A Guide to Eternity. Edited by J. W. Stanbridge, B.D.
The Psalms of David. Edited by B. W. Randolph, D.D.
Lyra Apostolica. By Cardinal Newman and others. Edited by
Canon Scott Holland and Canon H. C. Beeching, M.A.
The Inner Way. By J. Tauler. Edited by A. W. Hutton, M.A.
The Thoughts of Pascal. Edited by C. S. Jerram, M.A.
On the Love of God. By St. Francis de Sales. Edited by W. J.
Knox-Little, M.A.
A Manual of Consolation from the Saints and Fathers.
Edited by J. H. Burn, B.D.
The Song of Songs. Edited by B. Blaxland, M.A.
The Devotions of St. Anselm. Edited by C. C. J. Webb, M.A.
Grace Abounding. By John Bunyan. Edited by S. C. Freer,
M.A.
Bishop Wilson’s Sacra Privata. Edited by A. E. Burn, B.D.
Lyra Sacra: A Book of Sacred Verse. Edited by H. C.
Beeching, M.A., Canon of Westminster.
A Day Book from the Saints and Fathers. Edited by J. H.
Burn, B.D.
Heavenly Wisdom. A Selection from the English Mystics.
Edited by E. C. Gregory.
Light, Life, and Love. A Selection from the German Mystics.
Edited by W. R. Inge, M.A.
An Introduction to the Devout Life. By St. Francis de
Sales. Translated and Edited by T. Barns, M.A.

Methuen’s Standard Library


In Sixpenny Volumes.
The Standard Library is a new series of volumes containing
the great classics of the world, and particularly the finest works
of English literature. All the great masters will be represented,
either in complete works or in selections. It is the ambition of
the publishers to place the best books of the Anglo-Saxon race
within the reach of every reader, so that the series may
represent something of the diversity and splendour of our
English tongue. The characteristics of The Standard Library
are four:—1. Soundness of Text. 2. Cheapness. 3. Clearness
of Type. 4. Simplicity. The books are well printed on good
paper at a price which on the whole is without parallel in the
history of publishing. Each volume contains from 100 to 250
pages, and is issued in paper covers, Crown 8vo, at Sixpence
net, or in cloth gilt at One Shilling net. In a few cases long books
are issued as Double Volumes or as Treble Volumes.
The following books are ready with the exception of those
marked with a †, which denotes that the book is nearly ready:—
The Meditations of Marcus Aurelius. The translation is by
R. Graves.
The Novels of Jane Austen. In 5 volumes. Vol. i.—Sense
and Sensibility.
Essays and Counsels and The New Atlantis. By Francis
Bacon, Lord Verulam.
Religio Medici and Urn Burial. By Sir Thomas Browne. The
text has been collated by A. R. Waller.
The Pilgrim’s Progress. By John Bunyan.
Reflections on the French Revolution. By Edmund
Burke.
The Analogy of Religion, Natural and Revealed. By
Joseph Butler, D.D.
The Poems of Thomas Chatterton. In 2 volumes.

Vol. I.—Miscellaneous Poems.


†Vol. II.—The Rowley Poems.
† Vita Nuova. By Dante. Translated into English by D. G.
Rossetti.
Tom Jones. By Henry Fielding. Treble Vol.
Cranford. By Mrs. Gaskell.
The History of the Decline and Fall of the Roman
Empire. By Edward Gibbon. In 7 double volumes.

Vol. v. is nearly ready.

The Text and Notes have been revised by J. B. Bury,


Litt.D., but the Appendices of the more expensive
edition are not given.

†The Vicar of Wakefield. By Oliver Goldsmith.


The Poems and Plays of Oliver Goldsmith.
The Works of Ben Jonson.

†Vol. i.—The Case is Altered. Every Man in His Humour.


Every Man out of His Humour.

The text has been collated by H. C. Hart.

The Poems of John Keats. Double volume. The Text has


been collated by E. de Selincourt.
On the Imitation of Christ. By Thomas à Kempis.

The translation is by C. Bigg, D.D., Canon of Christ


Church.

A Serious Call to a Devout and Holy Life. By William


Law.
The Plays of Christopher Marlowe.

†Vol. I.—Tamburlane the Great. The Tragical History of


Dr. Faustus.

The Plays of Philip Massinger.


†Vol. I.—The Duke of Milan.

The Poems of John Milton. In 2 volumes.

Vol. I.—Paradise Lost.

The Prose Works of John Milton.

Vol. i.—Eikonoklastes and The Tenure of Kings and


Magistrates.

Select Works of Sir Thomas More.

Vol. I.—Utopia and Poems.

The Republic of Plato. Translated by Sydenham and Taylor.


Double Volume. The translation has been revised by W. H.
D. Rouse.
The Little Flowers of St. Francis. Translated by W.
Heywood.
The Works of William Shakespeare. In 10 volumes.
Vol. i.—The Tempest; The Two Gentlemen of Verona; The
Merry Wives of Windsor; Measure for Measure; The
Comedy of Errors.
Vol. ii.—Much Ado About Nothing; Love’s Labour’s Lost; A
Midsummer Night’s Dream; The Merchant of Venice; As
You Like It.
Vol. iii.—The Taming of the Shrew; All’s Well that Ends
Well; Twelfth Night; The Winter’s Tale.
Vol. IV.—The Life and Death of King John; The Tragedy of
King Richard the Second; The First Part of King Henry IV.;
The Second Part of King Henry IV.
Vol. V.—The Life of King Henry V.; The First Part of King
Henry VI.; The Second Part of King Henry VI.
The Life of Nelson. By Robert Southey.
The Natural History and Antiquities of Selborne. By
Gilbert White.

Half-Crown Library
Crown 8vo. 2s. 6d. net.
The Life of John Ruskin. By W. G. Collingwood, M.A. With
Portraits. Sixth Edition.
English Lyrics. By W. E. Henley. Second Edition.
The Golden Pomp. A Procession of English Lyrics. Arranged
by A. T. Quiller Couch. Second Edition.
Chitral: The Story of a Minor Siege. By Sir G. S. Robertson,
K.C.S.I. Third Edition. Illustrated.
Strange Survivals and Superstitions. By S. Baring-Gould.
Third Edition.
Yorkshire Oddities and Strange Events. By S. Baring-
Gould. Fourth Edition.
English Villages. By P. H. Ditchfield, M.A., F.S.A.
Illustrated. Second Edition.
A Book of English Prose. By W. E. Henley and C. Whibley.
The Land of the Black Mountain. Being a Description of
Montenegro. By R. Wyon and G. Prance. With 40
Illustrations.

Illustrated Pocket Library of Plain and Coloured


Books, The
Fcap 8vo. 3s. 6d. net each volume.
A series, in small form, of some of the famous illustrated
books of fiction and general literature. These are faithfully
reprinted from the first or best editions without introduction or
notes. The Illustrations are chiefly in colour.
COLOURED BOOKS
Old Coloured Books. By George Paston. With 16 Coloured
Plates. Fcap. 8vo. 2s. net.
The Life and Death of John Mytton, Esq. By Nimrod. With
18 Coloured Plates by Henry Alken and T. J. Rawlins.
Fourth Edition.
The Life of a Sportsman. By Nimrod. With 35 Coloured
Plates by Henry Alken.
Handley Cross. By R. S. Surtees. With 17 Coloured Plates
and 100 Woodcuts in the Text by John Leech. Second
Edition.
Mr. Sponge’s Sporting Tour. By R. S. Surtees. With 13
Coloured Plates and 90 Woodcuts in the Text by John
Leech.
Jorrocks’ Jaunts and Jollities. By R. S. Surtees. With 13
Coloured Plates by H. Alken. Second Edition.

This volume is reprinted from the extremely rare and


costly edition of 1843, which contains Alken’s very
fine illustrations instead of the usual ones by Phiz.

Ask Mamma. By R. S. Surtees. With 13 Coloured Plates and 70


Woodcuts in the Text by John Leech.
The Analysis of the Hunting Field. By R. S. Surtees. With 7
Coloured Plates by Henry Alken, and 43 Illustrations on
Wood.
The Tour of Dr. Syntax in Search of The Picturesque. By
William Combe. With 30 Coloured Plates by T. Rowlandson.
The Tour of Doctor Syntax in Search of Consolation. By
William Combe. With 24 Coloured Plates by T. Rowlandson.
The Third Tour of Doctor Syntax in Search of a Wife. By
William Combe. With 24 Coloured Plates by T. Rowlandson.
The History of Johnny Quae Genus: the Little Foundling of
the late Dr. Syntax. By the Author of ‘The Three Tours.’
With 24 Coloured Plates by Rowlandson.
The English Dance of Death, from the Designs of T.
Rowlandson, with Metrical Illustrations by the Author of
‘Doctor Syntax.’ Two Volumes.

This book contains 76 Coloured Plates.

The Dance of Life: A Poem. By the Author of ‘Doctor


Syntax.’ Illustrated with 26 Coloured Engravings by T.
Rowlandson.
Life in London: or, the Day and Night Scenes of Jerry
Hawthorn, Esq., and his Elegant Friend, Corinthian Tom.
By Pierce Egan. With 36 Coloured Plates by I. R. and G.
Cruikshank. With numerous Designs on Wood.
Real Life in London: or, the Rambles and Adventures of Bob
Tallyho, Esq., and his Cousin, The Hon. Tom Dashall. By an
Amateur (Pierce Egan). With 31 Coloured Plates by Alken
and Rowlandson, etc. Two Volumes.
The Life of an Actor. By Pierce Egan. With 27 Coloured
Plates by Theodore Lane, and several Designs on Wood.
The Vicar of Wakefield. By Oliver Goldsmith. With 24
Coloured Plates by T. Rowlandson.
The Military Adventures of Johnny Newcome. By an
Officer. With 15 Coloured Plates by T. Rowlandson.
The National Sports of Great Britain. With Descriptions
and 51 Coloured Plates by Henry Alken.

This book is completely different from the large folio


edition of ‘National Sports’ by the same artist, and
none of the plates are similar.

The Adventures of a Post Captain. By A Naval Officer.


With 24 Coloured Plates by Mr. Williams.
Gamonia: or, the Art of Preserving Game; and an Improved
Method of making Plantations and Covers, explained and
illustrated by Lawrence Rawstorne, Esq. With 15 Coloured
Plates by T. Rawlins.
An Academy for Grown Horsemen: Containing the
completest Instructions for Walking, Trotting, Cantering,
Galloping, Stumbling, and Tumbling. Illustrated with 27
Coloured Plates, and adorned with a Portrait of the Author.
By Geoffrey Gambado, Esq.
Real Life in Ireland, or, the Day and Night Scenes of Brian
Boru, Esq., and his Elegant Friend, Sir Shawn O’Dogherty.
By a Real Paddy. With 19 Coloured Plates by Heath, Marks,
etc.
The Adventures of Johnny Newcome in the Navy. By
Alfred Burton. With 16 Coloured Plates by T. Rowlandson.
The Old English Squire: A Poem. By John Careless, Esq.
With 20 Coloured Plates after the style of T. Rowlandson.
*The English Spy. By Bernard Blackmantle. With 72
Coloured Plates by R. Cruikshank, and many Illustrations
on wood. Two Volumes.

PLAIN BOOKS
The Grave: A Poem. By Robert Blair. Illustrated by 12
Etchings executed by Louis Schiavonetti from the original
Inventions of William Blake. With an Engraved Title Page
and a Portrait of Blake by T. Phillips, R.A.

The illustrations are reproduced in photogravure.

Illustrations of the Book of Job. Invented and engraved


by William Blake.

These famous Illustrations—21 in number—are


reproduced in photogravure.

Æsop’s Fables. With 380 Woodcuts by Thomas Bewick.


Windsor Castle. By W. Harrison Ainsworth. With 22 Plates
and 87 Woodcuts in the Text by George Cruikshank.
The Tower of London. By W. Harrison Ainsworth. With 40
Plates and 58 Woodcuts in the Text by George Cruikshank.
Frank Fairlegh. By F. E. Smedley. With 30 Plates by George
Cruikshank.
Handy Andy. By Samuel Lover. With 24 Illustrations by the
Author.
The Compleat Angler. By Izaak Walton and Charles Cotton.
With 14 Plates and 77 Woodcuts in the Text.

This volume is reproduced from the beautiful edition of


John Major of 1824.

The Pickwick Papers. By Charles Dickens. With the 43


Illustrations by Seymour and Phiz, the two Buss Plates, and
the 32 Contemporary Onwhyn Plates.

Junior Examination Series


Edited by A. M. M. Stedman, M.A. Fcap. 8vo. 1s.
This series is intended to lead up to the School Examination
Series, and is intended for the use of teachers and students, to
supply material for the former and practice for the latter. The
papers are carefully graduated, cover the whole of the subject
usually taught, and are intended to form part of the ordinary
class work. They may be used vivâ voce or as a written
examination.
Junior French Examination Papers. By F.Jacob, M.A.
Second Edition.
Junior Latin Examination Papers. By C. G. Botting, B.A.
Fourth Edition.
Junior English Examination Papers. By W. Williamson,
B.A.
Junior Arithmetic Examination Papers. By W. S. Beard.
Third Edition.
Junior Algebra Examination Papers. By S. W. Finn, M.A.
Junior Greek Examination Papers. By T. C. Weatherhead,
M.A.
Junior General Information Examination Papers. By W.
S. Beard.
A Key to the above. Crown 8vo. 3s. 6d. net.
Junior Geography Examination Papers. By W. G. Baker,
M.A.
Junior German Examination Papers. By A. Voegelin, M.A.

Junior School-Books
Edited by O. D. Inskip, LL.D., and W. Williamson, B.A.

A series of elementary books for pupils in lower forms, simply


written by teachers of experience.
A Class-Book of Dictation Passages. By W. Williamson,
B.A. Twelfth Edition. Cr. 8vo. 1s. 6d.
The Gospel According to St. Matthew. Edited by E. Wilton
South, M.A. With Three Maps. Cr. 8vo. 1s. 6d.
The Gospel According to St. Mark. Edited by A. E. Rubie,
D.D. With Three Maps. Cr. 8vo. 1s. 6d.
A Junior English Grammar. By W. Williamson, B.A. With
numerous passages for parsing and analysis, and a chapter
on Essay Writing. Third Edition. Cr. 8vo. 2s.
A Junior Chemistry. BY E. A. Tyler, B. A., F.C.S. With 78
Illustrations. Second Edition. Cr. 8vo. 2s. 6d.
The Acts of the Apostles. Edited by A. E. Rubie, D.D. Cr.
8vo. 2s.
A Junior French Grammar. By L. A. Sornet and M. J.
Acatos. Cr. 8vo. 2s.
Elementary Experimental Science. Physics by W. T.
Clough, A.R.C.S. Chemistry by A. E. Dunstan, B.Sc. With 2
Plates and 154 Diagrams. Fourth Edition. Cr. 8vo. 2s. 6d.
A Junior Geometry. By Noel S. Lydon. With 276 Diagrams.
Second Edition. Cr. 8vo. 2s.
A Junior Magnetism and Electricity. By W. T. Clough.
Illustrated. Cr. 6vo. 2s. 6d.
Elementary Experimental Chemistry. By A. E. Dunstan,
B.Sc. With 4 Plates and 109 Diagrams. Cr. 8vo. 2s.
A Junior French Prose Composition. By R. R. N. Baron,
M.A. Second Edition. Cr. 8vo. 2s.
The Gospel According to St. Luke. With an Introduction
and Notes by William Williamson, B.A. With Three Maps.
Cr. 8vo. 2s.

Leaders of Religion
Edited by H. C. BEECHING, M.A., Canon of Westminster. With
Portraits. Cr. 8vo. 2s. net.
A series of short biographies of the most prominent leaders of
religious life and thought of all ages and countries.
Cardinal Newman. By R. H. Hutton.
John Wesley. By J. H. Overton, M.A.
Bishop Wilberforce. By G. W. Daniell, M.A.
Cardinal Manning. By A. W. Hutton, M.A.
Charles Simeon. By H. C. G. Moule, D.D.
John Keble. By Walter Lock. D.D.
Thomas Chalmers. By Mrs. Oliphant.
Lancelot Andrewes. By R. L. Ottley, D.D. Second Edition.
Augustine of Canterbury. By E. L. Cutts, D.D.
William Laud. By W. H. Hutton, M.A. Third Edition.
John Knox. By F. MacCunn. Second Edition.
John Howe. By R. F. Horton, D.D.
Bishop Ken. By F. A. Clarke, M.A.
George Fox, the Quaker. By T. Hodgkin, D.C.L. Third
Edition.
John Donne. By Augustus Jessopp, D.D.
Thomas Cranmer. By A. J. Mason, D.D.
Bishop Latimer. By R. M. Carlyle and A. J. Carlyle, M.A.
Bishop Butler. By W. A. Spooner, M.A.

Little Blue Books, The


General Editor, E.V. Lucas.

Illustrated, Demy 16mo. 2s. 6d.


A series of books for children. The aim of the editor is to get
entertaining or exciting stories about normal children, the
moral of which is implied rather than expressed.
1. The Castaways of Meadowbank. By Thomas Cobb.
2. The Beechnut Book. By Jacob Abbott. Edited by E. V.
Lucas.
3. The Air Gun. By T. Hilbert.
4. A School Year. By Netta Syrett.
5. The Peeles at the Capital. By Roger Ashton.
6. The Treasure of Princegate Priory. By T. Cobb.
7. Mrs. Barberry’s General Shop. By Roger Ashton.
8. A Book of Bad Children. By W. T. Webb.
9. The Lost Ball. By Thomas Cobb.

Little Books on Art


With many Illustrations. Demy 16mo. 2s. 6d. net.
A series of monographs in miniature, containing the
complete outline of the subject under treatment and rejecting
minute details. These books are produced with the greatest
care. Each volume consists of about 200 pages, and contains
from 30 to 40 illustrations, including a frontispiece in
photogravure.
Greek Art. H. B. Walters. Third Edition.
Bookplates. E. Almack.
Reynolds. J. Sime. Second Edition.
Romney. George Paston.
Watts. R. E. D. Sketchley.
Leighton. Alice Corkran.
Velasquez. Wilfrid Wilberforce and A. R. Gilbert.
Greuze and Boucher. Eliza F. Pollard.
Vandyck. M. G. Smallwood.
Turner. Frances Tyrell-Gill.
Dürer. Jessie Allen.
Hoppner. H. P. K. Skipton.
Holbein. Mrs. G. Fortescue.
Burne-Jones. Fortunée de Lisle. Second Edition.
Rembrandt. Mrs. E. A. Sharp
Corot. Alice Pollard and Ethel Birnstingl.
Raphael. A. R. Dryhurst.
Millet. Netta Peacock.
Illuminated MSS. J. W. Bradley.
Christ in Art. Mrs. Henry Jenner.
Jewellery. Cyril Davenport.
Claude. Edward Dillon.
The Arts of Japan. Edward Dillon.

Little Galleries, The


Demy 16mo. 2s. 6d. net.
A series of little books containing examples of the best work
of the great painters. Each volume contains 20 plates in
photogravure, together with a short outline of the life and work
of the master to whom the book is devoted.
A Little Gallery of Reynolds.
A Little Gallery of Romney.
A Little Gallery of Hoppner.
A Little Gallery of Millais.
A Little Gallery of English Poets.

Little Guides, The


Small Pott 8vo, cloth, 2s. 6d. net.; leather, 3s. 6d. net.
Oxford and its Colleges. By J. Wells, M.A. Illustrated by E.
H. New. Seventh Edition.
Cambridge and its Colleges. By A. Hamilton Thompson.
Illustrated by E. H. New. Second Edition.
The Malvern Country. By B. C. A. Windle, D.Sc., F.R.S.
Illustrated by E. H. New.
Shakespeare’s Country. By B. C. A. Windle, D.Sc., F.R.S.
Illustrated by E. H. New. Second Edition.
Sussex. By F. G. Brabant, M.A. Illustrated by E. H. New.
Second Edition.
Westminster Abbey. By G. E. Troutbeck. Illustrated by F. D.
Bedford.
Norfolk. By W. A. Dutt. Illustrated by B. C. Boulter.
Cornwall. By A. L. Salmon. Illustrated by B. C. Boulter.
Brittany. By S. Baring-Gould. Illustrated by J. Wylie.
Hertfordshire. By H. W. Tompkins, F.R.H.S. Illustrated by
E. H. New.
The English Lakes. By F. G. Brabant, M.A. Illustrated by E.
H. New.
Kent. By G. Clinch. Illustrated by F. D. Bedford.
Rome. By C. G. Ellaby. Illustrated by B. C. Boulter.
The Isle of Wight. By G. Clinch. Illustrated by F. D. Bedford.
Surrey. By F. A. H. Lambert. Illustrated by E. H. New.
Buckinghamshire. By E. S. Roscoe. Illustrated by F. D.
Bedford.
Suffolk. By W. A. Dutt. Illustrated by J. Wylie.
Derbyshire. By J. C. Cox, LL.D., F.S.A. Illustrated by J. C.
Wall.
The North Riding of Yorkshire. By J. E. Morris. Illustrated
by R. J. S. Bertram.
Hampshire. By J. C. Cox. Illustrated by M. E. Purser.
Sicily. By F. H. Jackson. With many Illustrations by the
Author.
Dorset. By Frank R. Heath. Illustrated.
Cheshire. By W. M. Gallichan. Illustrated by Elizabeth
Hartley.
Northamptonshire. By Wakeling Dry. Illustrated.
The East Riding of Yorkshire. By J. E. Morris. Illustrated.
Oxfordshire. By F. G. Brabant. Illustrated by E. H. New.
St. Paul’s Cathedral. By George Clinch. Illustrated by
Beatrice Alcock.

Little Library, The


With Introductions, Notes, and Photogravure Frontispieces.

Small Pott 8vo. Each Volume; cloth, 1s. 6d. net; leather, 2s. 6d.
net.
A series of small books under the above title, containing some
of the famous works in English and other literatures, in the
domains of fiction, poetry, and belles lettres. The series also
contains volumes of selections in prose and verse. The books
are edited with the most scholarly care. Each one contains an
introduction which gives (1) a short biography of the author; (2)
a critical estimate of the book. Where they are necessary, short
notes are added at the foot of the page.
Each volume has a photogravure frontispiece, and the books
are produced with great care.
Anon. ENGLISH LYRICS, A LITTLE BOOK OF.
Austen (Jane). PRIDE AND PREJUDICE. Edited by E. V.
Lucas. Two Volumes.
NORTHANGER ABBEY. Edited by E. V. Lucas.
Bacon (Francis). THE ESSAYS OF LORD BACON. Edited
by Edward Wright.
Barham (R. H.). THE INGOLDSBY LEGENDS. Edited by J.
B. Atlay. Two Volumes.
Barnett (Mrs. P. A.). A LITTLE BOOK OF ENGLISH
PROSE.
Beckford (William). THE HISTORY OF THE CALIPH
VATHEK. Edited by E. Denison Ross.
Blake (William). SELECTIONS FROM WILLIAM BLAKE.
Edited by M. Perugini.
Borrow (George). LAVENGRO. Edited by F. Hindes
Groome. Two Volumes.
THE ROMANY RYE. Edited by John Sampson.
Browning (Robert). SELECTIONS FROM THE EARLY
POEMS OF ROBERT BROWNING. Edited by W. Hall
Griffin, M.A.
Canning (George). SELECTIONS FROM THE ANTI-
JACOBIN: with George Canning’s additional Poems.
Edited by Lloyd Sanders.
Cowley (Abraham). THE ESSAYS OF ABRAHAM
COWLEY. Edited by H. C. Minchin.
Crabbe (George). SELECTIONS FROM GEORGE
CRABBE. Edited by A. C. Deane.
Craik (Mrs.). JOHN HALIFAX, GENTLEMAN. Edited by
Anne Matheson. Two Volumes.
Crashaw (Richard). THE ENGLISH POEMS OF
RICHARD CRASHAW. Edited by Edward Hutton.
Dante (Alighieri). THE INFERNO OF DANTE. Translated
by H. F. Cary. Edited by Paget Toynbee, M.A., D.Litt.
THE PURGATORIO OF DANTE. Translated by H. F. Cary.
Edited by Paget Toynbee, M.A., D.Litt.
THE PARADISO OF DANTE. Translated by H. F. Cary.
Edited by Paget Toynbee, M.A., D.Litt.
Darley (George). SELECTIONS FROM THE POEMS OF
GEORGE DARLEY. Edited by R. A. Streatfeild.
Deane (A. C.). A LITTLE BOOK OF LIGHT VERSE.
Dickens (Charles). CHRISTMAS BOOKS. Two Volumes.
Ferrier (Susan). MARRIAGE. Edited by A. Goodrich-
Freer and Lord Iddesleigh. Two Volumes.
THE INHERITANCE. Two Volumes.
Gaskell (Mrs.). CRANFORD. Edited by E. V. Lucas. Second
Edition.
Hawthorne (Nathaniel). THE SCARLET LETTER. Edited
by Percy Dearmer.
Henderson (T. F.). A LITTLE BOOK OF SCOTTISH
VERSE.
Keats (John). POEMS. With an Introduction by L. Binyon,
and Notes by J. Masefield.
Kinglake (A. W.). EOTHEN. With an Introduction and
Notes. Second Edition.
Lamb (Charles). ELIA, AND THE LAST ESSAYS OF ELIA.
Edited by E. V. Lucas.
Locker (F.). LONDON LYRICS. Edited by A. D. Godley,
M.A. A reprint of the First Edition.
Longfellow (H. W.). SELECTIONS FROM LONGFELLOW.
Edited by L. M. Faithfull.
Marvell (Andrew). THE POEMS OF ANDREW MARVELL.
Edited by E. Wright.
Milton (John). THE MINOR POEMS OF JOHN MILTON.
Edited by H. C. Beeching, M.A., Canon of Westminster.
Moir (D. M.). MANSIE WAUCH. Edited by T. F.
Henderson.
Nichols (J. B. B.). A LITTLE BOOK OF ENGLISH
SONNETS.
Rochefoucauld (La). THE MAXIMS OF LA
ROCHEFOUCAULD. Translated by Dean Stanhope. Edited
by G. H. Powell.
Smith (Horace and James). REJECTED ADDRESSES.
Edited by A. D. Godley, M.A.
Sterne (Laurence). A SENTIMENTAL JOURNEY. Edited
by H. W. Paul.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookmass.com

You might also like