Hacking with Spring Boot 2.3: Reactive Edition
Table of Contents
Copyright
Hacking with Spring Boot 2.3:
Reactive Edition
2020 Greg L. Turnquist
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
All opinions stated are the authors and do not necessarily reflect those of the Spring team, Pivotal Software, VMware, Dell EMC, or any other entity. Any usage of "Spring", "Spring Boot", "Spring Framework", "Project Reactor", any other portfolio project, "Pivotal", "VMware", "Testcontainers", "RabbitMQ", Docker", "MongoDB", or any other entity is completely unaffiliated with its owners. Any excerpts and usages thereof are strictly in the spirit of "fair use."
Certain outputs have been edited to fit the format of this book. Nothing of critical value has been left out on purpose.
All rendering and typesetting performed by Asciidoctor, Asciidoctor PDF, and Asciidoctor EPUB3. Fonts include Noto Serif
for prose and Fira Code
for code. Special thanks to Dan Allen and the Asciidoctor community for their support in making this book possible.
Published: May 2020
Greg L. Turnquist
c/o Hacking with Spring Boot
P.O. Box 4042
Clarksville, TN 37043
USA
GregLTurnquist.com/hacking-with-spring-boot
Credits
Author Greg L. Turnquist Foreword Dr. Dave Syer Editor Doug Warren Cover AMDesign Studios Reviewers Sergei Egorov
Martin Frstenau
Chua Wen Ching
Dedication
To those that have spoken in front of crowds,
To those that have launched user groups with only two people,
To those that have traveled the globe to share their love of Spring,
To those that were the first at their company to suggest using it,
This is book is dedicated to you,
for you are the true heroes of this rich and vibrant community.
Foreword
Spring Boot has been such a success that its probably not wrong now to describe it in 2020 as "mainstream." Practically every Java developer will know something about it, and many, maybe even the majority, will have used it in anger. But theres always something new to learn, and there are always new problems to solve in software engineeringthats what makes it so rewarding in the end. Theres always something new to invent, too, and having the skill and opportunity to create code is extremely rewarding, intellectually and in other ways. One of the goals of Spring Boot is shared with the author of this book, and that is to get your ideas down into code as quickly and efficiently as possible, so you can get it to the most special place: Production. I wish you a short and pleasant journey, or maybe a long series of short and pleasant journeys.
In this book, Greg has picked some of the newest ideas in Spring Boot and applied them to some old, well-seasoned favourite problems that you will have experienced as Java developers. What better way to learn something new than to look at it through the lens of tasks that we all have to solve, nearly every day: creating HTTP endpoints, securing them, connecting to databases, writing tests, sending messages? The book adds some new angles to these old chestnuts by applying modern ideas and tools. Read it and you will learn about Reactive Streams, hypermedia, RSocket and OpenID, all from the most practical and pragmatic of standpoints.
There are more things to Spring Boot than just main methods, embedded containers, autoconfiguration and management endpoints. The pure joy of getting started with a fully featured Spring application in a few lines of code cannot be understated, for instance. I invite you to dip into this book, break out an editor or an IDE and crank up some applications for yourself. Greg has been an important member of the Spring Boot team, despite having a day job doing other things in the Spring Engineering effort, and we can be grateful for that as well as the effort he has lavished on this excellent book. He has always been an educator and an informer, as well as an engineer, and this shows through very clearly in the book. When I read it I can hear Gregs voice, and his personality, very clearly, and it is always calm, but enthusiastic, with a touch of humour. Read it yourself and enjoycoding with Spring is still fun after all these years!
Dr. Dave Syer
Senior Consulting Engineer and co-founder of Spring Boot
AbouttheAuthor
Greg L. Turnquist works on the Spring team as a principal developer at VMware. He is a committer to Spring HATEOAS, Spring Data, Spring Boot, R2DBC, and Spring Session for MongoDB. He also wrote Packts best-selling title, Learning Spring Boot 2.0 2nd Edition. He co-founded the Nashville Java User Group in 2010 and hasnt met a Java app (yet) that he doesnt like.
Follow him on Twitter @gregturn and subscribe for all his Spring Boot videos at YouTube.com/GregTurnquist.
Preface
What this book covers
Chapter 1, Building a Web App with Spring Boot - Learn how to build web applications using Spring WebFlux.
Chapter 2, Data Access with Spring Boot - Access reactive data stores using Spring Data.
Chapter 3, Developer Tools for Spring Boot - Enhance your developer experience with all the tools afforded by Spring Boot.
Chapter 4, Testing with Spring Boot - Get a hold of reactive testing tools and how Spring Boot empowers testing your applications.
Chapter 5, Operations with Spring Boot - See how to manage your applications after they go to production.
Chapter 6, Building APIs with Spring Boot - Build JSON-based APIs using different tactics and tools from the Spring portfolio.
Chapter 7, Messaging with Spring Boot - Create asynchronous, message-based solutions using Spring Boot and Testcontainers.
Chapter 8, RSocket with Spring Boot - Discover a protocol that has reactive baked right in and supports multiple ways to communicate.
Chapter 9, Securing your Application with Spring Boot - Learn how secure your application with the most powerful tools available.
What you need for this book
Spring Boot 2.3 supports Java 8 and higher. This book is written using Java 8. Use sdkman to install, manage, and even switch between different distributions and versions of Java.
Spring Boot 2.3 is able to bake Docker containers. There is also Docker-based testing support through 3rd party tools like Testcontainers. For those sections, youll need to install Docker.
If you use Mac, you should consider Homebrew as an alternative package manager for certain utilities.
You need either an IDE or a good editor. Recommended options include:
- IDE
- IntelliJ IDEA
- Spring Tool Suite
- VS Code
- Eclipse
- Editor
Who should read this book
This book is to help developers new to Spring Boot as well as experienced Spring developers.
It shows how to get operational, fast, with some of the best coding practices available.