Skip to main content
main-content
Top

About this book

Get started with Spring Framework 5 and its ecosystem, with a guide to the working practices in modern development. This book will teach you how to use the Spring Framework to build Java-based applications, web applications, and microservices. You’ll see how Spring has drastically and positively affected the way we program and design applications in Java.
Beginning Spring 5 discusses how you can build apps with the Spring mindset and what the benefits of that mindset are. Along the way you will learn many aspects of the Spring ecosystem with easy-to-understand applications designed to teach you not only the technology, but also the practices that benefit the most from Spring.

What You Will LearnDiscover the most common use cases encountered in the real world
Create reliable, tested, modular software, building skills that will translate well across all languages and environments.
Integrate and use data access and persistence frameworks such as Hibernate, JPA, and MongoDB
Program functional or reactive Java with the latest Spring 5 features including WebFlux

Who This Book Is For
Those who are new to Spring or for those who have experience with Spring but want to learn what's new in Spring 5. This book assumes you have some prior coding experience in Java at least.

Table of Contents

Chapter 1. History and Justification

Abstract
Spring is an application framework providing dependency injection features for the Java Virtual Machine – features that enable testability, reliability, and flexibility to application developers. It changed how Java is developed, and here’s how and why.
Joseph B. Ottinger, Andrew Lombardi

Chapter 2. Hello, World!

Abstract
It seems appropriate to start learning about Spring by building out our first example as a simple "Hello, World!" application. In this chapter, we’re going to take a look at the tools and libraries we’re going to rely on – in particular, Gradle and TestNG – and build a simple application to demonstrate how we validate that our application works as designed. Then – at last – we’ll leverage Spring in our application. This way, we’ll establish the knowledge we’ll need to make sense of the rest of the book.
Joseph B. Ottinger, Andrew Lombardi

Chapter 3. Configuration and Declaration of Beans

Abstract
In this chapter, we’re going to explore a decent subset of Spring configuration, and we’re going to shift attention away from "Hello, World" into a simple application that will allow us to explore features and configuration. We’ll introduce the sample application first, then walk through a few different ways to configure it. There’s a lot of code here, much of it redundant on the surface, but we’ll use some base classes to help reduce the tendency to repeat ourselves.
Joseph B. Ottinger, Andrew Lombardi

Chapter 4. Lifecycle

Abstract
In this chapter, we’ll expand on our sample application and learn about the lifecycle options in Spring. We’ll introduce how to invoke methods when Spring beans are created or destroyed and how to do so via multiple configurable options either using the Spring XML file, annotations, or the programmatic configurations, all of which were used in Chapter 3.
Joseph B. Ottinger, Andrew Lombardi

Chapter 5. Spring and Jakarta EE

Abstract
Spring can certainly be used in a standalone environment, but the most common environment for Spring has historically been in an enterprise environment, powering web applications and backend services in a managed server. This chapter will demonstrate some aspects of integration in a Jakarta EE container (formerly known as Java EE, or J2EE, or maybe even just "Tomcat" depending on your level of exposure, currency, and experience).
Joseph B. Ottinger, Andrew Lombardi

Chapter 6. Spring Web

Abstract
Spring Web is a framework that provides a Model View Controller (MVC) architecture to develop applications with Spring for the Web. In the previous chapter, we built out several servlets running within the Spring framework, but aside from the beans and other management aspects you get baked into Spring, we were still using regular servlets in the previous chapter. And as we saw in the previous chapter, nothing stops you from doing this; however as we’ll hopefully be able to show, using this module will save you loads of time.
Joseph B. Ottinger, Andrew Lombardi

Chapter 7. Spring Boot

Abstract
So far, we’ve looked at dependency injection and various configuration approaches, and we’ve explored deploying some web services into Apache Tomcat. Along the way we’ve used a small set of Spring modules, picking and choosing as needed. It’s time for us to switch gears and look at Spring Boot, which is a project structure generally aimed at microcontainers; Spring Boot gives us an easier way to get larger feature sets out of Spring and offers an integrated set of services aimed at deploying running applications without having to rely on traditional Jakarta EE services like Apache Tomcat.
Joseph B. Ottinger, Andrew Lombardi

Chapter 8. Spring Data Access with JdbcTemplate

Abstract
It’s time we started looking at how we actually access data. Spring has multiple ways of accessing data; here, we’re going to look at JdbcTemplate, a facade that provides trivial access to common operations, and we’re going to address some of Chapter 7’s other issues with data access.
Joseph B. Ottinger, Andrew Lombardi

Chapter 9. Persistence with Spring and Spring Data

Abstract
In Chapter 8 we finally stopped looking at configuration and presentation mechanisms, and we looked at accessing a relational database with JdbcTemplate. In this chapter, we’re going to look at accessing data again – with a Spring project called "Spring Data," which can provide a mostly data-agnostic view of data access.
Joseph B. Ottinger, Andrew Lombardi

Chapter 10. Spring Security

Abstract
Security is critical in any application with access to live information – even public information. Security means controlling access to features and information; unless Annie is specifically granted access to Frank’s information, Frank’s data should be safe and, from Annie’s perspective, invisible. Naturally, Spring has a powerful and capable security project – called, of all things, Spring Security – that allows you to control nearly every aspect of application security.
Joseph B. Ottinger, Andrew Lombardi

Chapter 11. Next Steps

Abstract
By now, we’ve read about Spring and dependency injection, along with topics like web services (particularly REST services), transaction, persistence, and security. These are likely to be the "most important" parts of the Spring ecosystem, generally speaking, but we’ve barely scratched the surface of the Spring ecosystem itself, much less projects that use Spring without being part of the Spring project.
Joseph B. Ottinger, Andrew Lombardi
Additional information