front matter

preface

Spring entered the development world more than 18 years ago with the fundamental mission of making Java application development easier. Originally, that meant offering a lightweight alternative to EJB 2.x. But Spring was just getting started. Over the years, Spring expanded its mission of simplicity to address common development challenges, including persistence, security, integration, cloud computing, and others.

Although Spring is closing in on two decades of enabling and simplifying enterprise Java development, it shows no signs of slowing down. Spring continues to address Java development challenges, whether it be creating an application deployed to a conventional application server or a containerized application deployed to a Kubernetes cluster in the cloud. And with Spring Boot providing autoconfiguration, build dependency help, and runtime monitoring, there has never been a better time to be a Spring developer!

This edition of Spring in Action is your guide to Spring and Spring Boot and has been updated to reflect the best of what both have to offer. Even if you’re new to Spring, you’ll have your first Spring application up and running before the end of the first chapter. As the book progresses, you’ll learn how to create web applications, work with data, secure your application, and manage application configuration. Next, you’ll explore options for integrating your Spring applications with other applications and how to benefit from reactive programming in your Spring applications, including the new RSocket communication protocol. As the book draws to a close, you’ll see how to prepare your application for production and learn options for deploying.

Whether you’re new to Spring or have many years of Spring development to your credit, this is your next step in your journey. I’m excited for you and happy to bring this guide to you. I look forward to seeing what you create with Spring!

acknowledgments

One of the most amazing things that Spring and Spring Boot do is automatically provide all of the foundational plumbing for an application, leaving you as a developer to focus primarily on the logic that’s unique to your application. Unfortunately, no such magic exists for writing a book. Or does it?

At Manning, several people worked their magic to make sure that this book is the best it can possibly be. Many thanks in particular to my development editor, Jenny Stout, and to production editor, Deirdre Hiam, copy editor, Pamela Hunt, graphics editor, Jennifer Houle, and the entire production team for their wonderful work in making this book a reality.

As the book was forming, we had several peer reviewers take an early look, give us feedback, and help make sure that the book stayed on target and covered the right stuff. For this, my thanks go to Al Pezewski, Alessandro Campeis, Becky Huett, Christian Kreutzer-Beck, Conor Redmond, David Paccoud, David Torrubia Iñigo, David Witherspoon German Gonzalez-Morris, Iain Campbell, Jon Guenther, Kevin Liao, Mark Dechamps, Michael Bright, Philippe Vialatte, Pierre-Michel Ansel, Tony Sweets, William Fly, and Zorodzayi Mukuya.

I absolutely must give a shout out to everyone on the Spring engineering team. You consistently produce some of the most incredible stuff I’ve ever worked with, and I am proud to consider you my colleagues.

Many thanks go to my fellow speakers on the No Fluff/Just Stuff tour. I continue to learn so much from every one of you. And many thanks to those of you who have attended one of my sessions on the NFJS tour; although I’m the one at the front of the room, I often learn a lot from you, too.

As I did in the previous edition, I’d like to thank the Phoenicians. You know what you did.

Finally, to my beautiful wife, Raymie, the love of my life and my sweetest dream: thank you for your encouragement and for putting up with yet another book project. And to my sweet and wonderful girls, Maisy and Madi: I am so proud of you and of the amazing young ladies you are becoming. I love all of you more than you can possibly know or words can express.

about this book

Spring in Action, Sixth Edition, was written to equip you to build amazing applications using the Spring Framework, Spring Boot, and a variety of ancillary members of the Spring ecosystem. It begins by showing you how to develop web-based, database-backed Java applications with Spring and Spring Boot. It then expands on the essentials by showing how to integrate with other applications and programs using reactive types. Finally, it discusses how to ready an application for deployment.

Although all of the projects in the Spring ecosystem provide excellent documentation, this book does something that none of the reference documents do: provide a hands-on, project-driven guide to bringing the elements of Spring together and build a real application.

Who should read this book

Spring in Action, Sixth Edition, is for Java developers who want to get started with Spring Boot and the Spring Framework as well as for seasoned Spring developers who want to go beyond the basics and learn the newest features of Spring.

How this book is organized: A roadmap

The book has four parts spanning 18 chapters. Part 1 covers the foundational topics of building Spring applications:

  • Chapter 1 introduces Spring and Spring Boot and how to initialize a Spring project. In this chapter, you’ll take the first steps toward building a Spring application that you’ll expand on throughout the course of the book.

  • Chapter 2 discusses building the web layer of an application using Spring MVC. In this chapter, you’ll build controllers that handle web requests and views that render information in the web browser.

  • Chapter 3 delves into the backend of a Spring application, where data is persisted to a relational database.

  • Chapter 4 continues the subject of data persistence by looking at how to persist data to nonrelational databases, specifically, Cassandra and MongoDB.

  • In chapter 5, you’ll use Spring Security to authenticate users and prevent unauthorized access to an application.

  • Chapter 6 reveals how to configure a Spring application using Spring Boot configuration properties. You’ll also learn how to selectively apply configuration using profiles.

Part 2 covers topics that help integrate your Spring application with other applications:

  • Chapter 7 expands on the discussion of Spring MVC started in chapter 2, by looking at how to write and consume REST APIs in Spring.

  • Chapter 8 shows how to secure the APIs created in chapter 7, with Spring Security and OAuth 2.

  • Chapter 9 looks at using asynchronous communication to enable a Spring application to both send and receive messages using the Java Message Service, RabbitMQ, or Kafka.

  • Chapter 10 discusses declarative application integration using the Spring Integration project.

Part 3 explores the exciting new support for reactive programming in Spring:

  • Chapter 11 introduces Project Reactor, the reactive programming library that underpins Spring 5’s reactive features.

  • Chapter 12 revisits REST API development, introducing Spring WebFlux, a new web framework that borrows much from Spring MVC while offering a new reactive model for web development.

  • Chapter 13 takes a look at writing reactive data persistence with Spring Data to read and write data to Cassandra and Mongo databases.

  • Chapter 14 introduces RSocket, a new communication protocol that offers a reactive alternative to HTTP for creating APIs.

In part 4, you’ll ready an application for production and see how to deploy it:

  • Chapter 15 introduces the Spring Boot Actuator, an extension to Spring Boot that exposes the internals of a running Spring application as REST endpoints.

  • In chapter 16, you’ll see how to use Spring Boot Admin to put a user-friendly browser-based administrative application on top of the Actuator.

  • Chapter 17 discusses how to expose and consume Spring beans as JMX MBeans.

  • Finally, in chapter 18, you’ll see how to deploy your Spring application in a variety of production environments, including Kubernetes.

In general, developers new to Spring should start with chapter 1 and work through each chapter sequentially. Experienced Spring developers may prefer to jump in at any point that interests them. Even so, each chapter builds on the previous one, so there may be some context missing if you dive into the middle of the book.

About the code

This book contains many examples of source code, both in numbered listings and inline with normal text. In both cases, source code is formatted in a fixed-width font like this to separate it from ordinary text.

In many cases the original source code has been reformatted; we’ve added line breaks and reworked indentation to accommodate the available page space in the book. In rare cases, even this was not enough, and listings include line-continuation markers (). Additionally, comments in the source code have often been removed from the listings when the code is described in the text. Code annotations accompany many of the listings, highlighting important concepts.

You can get executable snippets of code from the liveBook (online) version of this book at https://livebook.manning.com/book/spring-in-action-sixth-edition. The complete code for the examples in the book is available for download from the Manning website at https://www.manning.com/books/spring-in-action-sixth-edition, and from GitHub at github.com/habuma/spring-in-action-6-samples.

Book forum

Purchase of Spring in Action, Sixth Edition, includes free access to liveBook, Manning’s online reading platform. Using liveBook’s exclusive discussion features, you can attach comments to the book globally or to specific sections or paragraphs. It’s a snap to make notes for yourself, ask and answer technical questions, and receive help from the author and other users. To access the forum, go to https://forums.manning.com/forums/spring-in-action-sixth-edition. You can also learn more about Manning’s forums and the rules of conduct at https://forums.manning.com/forums/about.

Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It is not a commitment to any specific amount of participation on the part of the author, whose contribution to the forum remains voluntary (and unpaid). We suggest you try asking the author some challenging questions lest his interest stray! The forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.

Other online resources

Need additional help?

about the author

Craig Walls is a senior engineer with VMware. He’s a zealous promoter of the Spring Framework, speaking frequently at local user groups and conferences and writing about Spring. When he’s not slinging code, Craig is planning his next trip to Disney World or Disneyland and spending as much time as he can with his wife, two daughters, three dogs, and a parrot.

about the cover illustration

The figure on the cover of Spring in Action, 6th edition, is “Le Caraco,” or an inhabitant of the province of Karak in southwest Jordan. Its capital is the city of Al-Karak, which boasts an ancient hilltop castle with magnificent views of the Dead Sea and surrounding plains. The illustration is taken from a French travel book, Encyclopédie des voyages by J. G. St. Sauveur, published in 1796. Travel for pleasure was a relatively new phenomenon at the time, and travel guides such as this one were popular, introducing both the tourist as well as the armchair traveler to the inhabitants of other regions of France and abroad.

The diversity of the drawings in the Encyclopédie des voyages speaks vividly of the distinctiveness and individuality of the world’s towns and provinces just 200 years ago. This was a time when the dress codes of two regions separated by a few dozen miles identified people uniquely as belonging to one or the other. The travel guide brings to life a sense of isolation and distance of that period, and of every other historic period except our own hyperkinetic present.

Dress codes have changed since then, and the diversity by region, so rich at the time, has faded away. It is now often hard to tell the inhabitants of one continent from another. Perhaps, trying to view it optimistically, we have traded a cultural and visual diversity for a more varied personal life—or a more varied and interesting intellectual and technical life. We at Manning celebrate the inventiveness, the initiative, and the fun of the computer business with book covers based on the rich diversity of regional life two centuries ago brought back to life by the pictures from this travel guide.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.12.140