O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Spring 5.0 Cookbook

Book Description

Over 100 hands-on recipes to build web applications easily and efficiently IN Spring 5.0

About This Book

  • Solve real-world problems using the latest features of the Spring framework like Reactive Streams and the Functional Web Framework.
  • Learn how to use dependency injection and aspect-oriented programming to write compartmentalized and testable code.
  • Understand when to choose between Spring MVC and Spring Web Reactive for your projects

Who This Book Is For

Java developers who would like to gain in-depth knowledge of how to overcome problems that they face while developing great Spring applications. It will also cater to Spring enthusiasts, users and experts who need an arena for comparative analysis, new ideas and inquiries on some details regarding Spring 5.0 and its previous releases. A basic knowledge of Spring development is essential

What You Will Learn

  • Understand how functional programming and concurrency in JDK 1.9 works, and how it will affect Spring 5.0
  • Learn the importance and application of reactive programming in creating services, and also the process of creating asynchronous MVC applications
  • Implement different Spring Data modules
  • Integrate Spring Security to the container
  • Create applications and deploy using Spring Boot
  • Conceptualize the architecture behind Microservices and learn the details of its implementation
  • Create different test cases for the components of Spring 5.0 components

In Detail

The Spring framework has been the go-to framework for Java developers for quite some time. It enhances modularity, provides more readable code, and enables the developer to focus on developing the application while the underlying framework takes care of transaction APIs, remote APIs, JMX APIs, and JMS APIs.

The upcoming version of the Spring Framework has a lot to offer, above and beyond the platform upgrade to Java 9, and this book will show you all you need to know to overcome common to advanced problems you might face.

Each recipe will showcase some old and new issues and solutions, right from configuring Spring 5.0 container to testing its components. Most importantly, the book will highlight concurrent processes, asynchronous MVC and reactive programming using Reactor Core APIs. Aside from the core components, this book will also include integration of third-party technologies that are mostly needed in building enterprise applications.

By the end of the book, the reader will not only be well versed with the essential concepts of Spring, but will also have mastered its latest features in a solution-oriented manner.

Style and Approach

This book follows a cookbook style approach, presenting a problem and showing you how to overcome it with useful recipes. The examples provided will help you code along as you learn.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Conventions
    6. Reader feedback
      1. Downloading the example code
      2. Downloading the color images of this book
      3. Errata
      4. Piracy
      5. Questions
  2. Getting Started with Spring
    1. Installing Java Development Kit 1.8
      1. Getting started
      2. How to do it...
      3. How it works...
    2. Installing Tomcat 9 and configuring HTTP/2
      1. Getting started
      2. How to do it...
      3. How it works...
    3. Installing STS Eclipse 3.8 IDE
      1. Getting started
      2. How to do it...
      3. How it works...
    4. Creating Eclipse projects using Maven
      1. Getting started
      2. How to do it...
      3. How it works...
    5. Creating Spring STS Eclipse projects using Gradle
      1. Getting started
      2. How to do it...
      3. How it works...
    6. Deploying Spring projects using Maven
      1. Getting started
      2. How to do it...
      3. How it works...
    7. Deploying Spring projects using Gradle
      1. Getting started
      2. How to do it...
      3. How it works...
    8. Installing the MySQL 5.7 database server
      1. Getting started
      2. How to do it...
      3. How it works...
    9. Installing the MongoDB 3.2 database server
      1. Getting started
      2. How to do it...
      3. How it works...
  3. Learning Dependency Injection (DI)
    1. Implementing a Spring container using XML
      1. Getting started
      2. How to do it...
      3. How it works...
    2. Implementing a Spring container using JavaConfig
      1. Getting started
      2. How to do it...
      3. How it works...
    3. Managing beans in an XML-based container
      1. Getting started
      2. How to do it...
      3. How it works...
    4. Managing beans in the JavaConfig container
      1. Getting started
      2. How to do it...
      3. How it works...
    5. Creating Singleton and Prototype beans
      1. Getting started
      2. How to do it...
      3. How it works...
    6. Defining eager and lazy spring beans
      1. Getting started
      2. How to do it...
      3. How it works...
    7. Creating an inner bean
      1. Getting started
      2. How to do it...
      3. How it works...
    8. Injecting Collections and Properties
      1. Getting started
      2. How to do it...
      3. How it works...
    9. Creating a Spring MVC using an XML-based approach
      1. Getting started
      2. How to do it...
      3. How it works...
    10. Creating a Spring MVC using the JavaConfig approach
      1. Getting started
      2. How to do it...
      3. How it works...
    11. Generating multiple ApplicationContexts
      1. Getting started
      2. How to do it...
      3. How it works...
    12. Using ResourceBundleMessageSource for Views
      1. Getting started
      2. How to do it...
      3. How it works...
  4. Implementing MVC Design Patterns
    1. Creating the simple @Controller
      1. Getting started
      2. How to do it...
      3. How it works...
    2. Creating a simple @Controller with method-level URL mapping
      1. Getting started
      2. How to do it...
      3. How it works...
    3. Designing a simple form @Controller
      1. Getting started
      2. How to do it...
      3. How it works...
    4. Creating a multi-action @Controller
      1. Getting started
      2. How to do it...
      3. How it works...
    5. Form validation and parameter type conversion
      1. Getting started
      2. How to do it...
      3. How it works...
    6. Creating request- and session-scoped beans
      1. Getting started
      2. How to do it...
      3. How it works...
    7. Implementing page redirection and Flash-scoped beans
      1. Getting started
      2. How to do it...
      3. How it works...
    8. Creating database connection pooling
      1. Getting started
      2. How to do it...
      3. How it works...
    9. Implementing the DAO layer using the Spring JDBC Framework
      1. Getting Started
      2. How to do it...
      3. How it works...
    10. Creating a service layer in an MVC application
      1. Getting started
      2. How to do it...
      3. How it works...
  5. Securing Spring MVC Applications
    1. Configuring Spring Security 4.2.2
      1. Getting started
      2. How to do it...
      3. How it works...
    2. Mapping sessions to channels and ports
      1. Getting started
      2. How to do it...
      3. How it works...
    3. Customizing the authentication process
      1. Getting started
      2. How to do it...
      3. How it works...
    4. Implementing authentication filters, login success, and failure handlers
      1. Getting started
      2. How to do it...
      3. How it works...
    5. Creating user details
      1. Getting started
      2. How to do it...
      3. How it works...
    6. Generating encrypted passwords
      1. Getting started
      2. How to do it...
      3. How it works...
    7. Applying Security to MVC methods
      1. Getting started
      2. How to do it...
      3. How it works...
    8. Creating roles and permissions from the database
      1. Getting started
      2. How to do it...
      3. How it works...
    9. Managing and storing sessions
      1. Getting started
      2. How to do it...
      3. How it works...
    10. Solving Cross-Site Request Forgery (CSRF) and session fixation attacks
      1. Getting started
      2. How to do it...
      3. How it works...
    11. Solving Cross-Site Scripting (XSS) and clickjacking attacks
      1. Getting started
      2. How to do it...
      3. How it works...
    12. Creating interceptors for login data validation
      1. Getting started
      2. How to do it...
      3. How it works...
  6. Cross-Cutting the MVC
    1. Logging and auditing service methods
      1. Getting started
      2. How to do it...
      3. How it works...
    2. Managing DAO transactions
      1. Getting started
      2. How to do it...
      3. How it works...
    3. Monitoring services and request handlers
      1. Getting started
      2. How to do it...
      3. How it works...
    4. Validating parameters and arguments
      1. Getting started
      2. How to do it...
      3. How it works...
    5. Managing exceptions
      1. Getting started
      2. How to do it...
      3. How it works...
    6. Implementing the caching mechanism
      1. Getting started
      2. How to do it...
      3. How it works...
    7. Intercepting request transactions
      1. Getting started
      2. How to do it...
      3. How it works...
    8. Implementing user authentication
      1. Getting started
      2. How to do it...
      3. How it works...
    9. Accessing with restrictions
      1. Getting started
      2. How to do it...
      3. How it works...
    10. Controlling concurrent user access
      1. Getting started
      2. How to do it...
      3. How it works...
    11. Implementing a mini-workflow using AOP
      1. Getting started
      2. How to do it...
      3. How it works...
  7. Functional Programming
    1. Implementing lambda expressions using anonymous inner classes
      1. Getting started
      2. How to do it...
      3. How it works...
    2. Implementing lambda expression using @FunctionInterface
      1. Getting started
      2. How to do it...
      3. How it works...
    3. Applying the built-in functional interfaces
      1. Getting started
      2. How to do it...
      3. How it works...
    4. Applying method and constructor references
      1. Getting started
      2. How to do it...
      3. How it works...
    5. Using the Stream API
      1. Getting started
      2. How to do it...
      3. How it works...
    6. Applying streams to collections
      1. Getting started
      2. How to do it...
      3. How it works...
    7. Applying streams to NIO 2.0
      1. Getting started
      2. How to do it...
      3. How it works...
    8. Using parallel streams
      1. Getting started
      2. How to do it...
      3. How it works...
  8. Reactive Programming
    1. Applying the observer design pattern using Reactive Streams
      1. Getting started
      2. How to do it...
      3. How it works...
    2. Creating Mono<T> and Flux<T> publishers
      1. Getting started
      2. How to do it...
      3. How it works...
    3. Implementing the Subscriber<T> interface
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Applying backpressure to Mono<T> and Flux<T>
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Managing task executions using Schedulers
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Creating concurrent and parallel emissions
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Managing continuous data emission
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Implementing Stream manipulation and transformation
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Testing Reactive data transactions
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Implementing Reactive events using RxJava 2.x
      1. Getting ready
      2. How to do it...
      3. How it works...
  9. Reactive Web Applications
    1. Configuring the TaskExecutor
      1. Getting started
      2. How to do it...
      3. How it works...
        1. SimpleAsyncTaskExecutor
        2. ThreadPoolTaskExecutor
        3. ConcurrentTaskExecutor
    2. Implementing @Async services
      1. Getting started
      2. How to do it...
      3. How it works...
    3. Creating asynchronous controllers
      1. Getting started
      2. How to do it...
      3. How it works...
    4. Creating @Scheduled services
      1. Getting started
      2. How to do it...
      3. How it works...
    5. Using Future<T> and CallableFuture<T>
      1. Getting started
      2. How to do it...
      3. How it works...
    6. Using Mono<T> and Flux<T> publishers for services
      1. Getting started
      2. How to do it...
      3. How it works...
    7. Creating Mono<T> and Flux<T> HTTP response
      1. Getting started
      2. How to do it...
      3. How it works...
    8. Integrating RxJava 2.0
      1. Getting started
      2. How to do it...
      3. How it works...
    9. Using FreeMarker to render Publisher<T> stream
      1. Getting started
      2. How to do it...
      3. How it works...
    10. Using Thymeleaf to render a Publisher<T> stream
      1. Getting started
      2. How to do it...
      3. How it works...
    11. Applying security on TaskExecutors
      1. Getting started
      2. How to do it...
      3. How it works...
  10. Spring Boot 2.0
    1. Building a non-reactive Spring MVC application
      1. Getting started
      2. How to do it...
      3. How it works...
    2. Configuring Logging
      1. Getting started
      2. How to do it...
      3. How it works...
    3. Adding JDBC Connectivity
      1. Getting started
      2. How to do it...
      3. How it works...
    4. Building a reactive Spring MVC application
      1. Getting started
      2. How to do it...
      3. How it works...
    5. Configuring Spring Security 5.x
      1. Getting started
      2. How to do it...
      3. How it works...
    6. Using reactive view resolvers
      1. Getting started
      2. How to do it...
      3. How it works...
    7. Using RouterFunction and HandlerFunction
      1. Getting started
      2. How to do it...
      3. How it works...
    8. Implementing Spring Data with JPA
      1. Getting started
      2. How to do it...
      3. How it works...
    9. Implementing REST services using @RestController and Spring REST
      1. Getting started
      2. How to do it...
      3. How it works...
    10. Applying Spring Cache
      1. Getting started
      2. How to do it...
      3. How it works...
  11. The Microservices
    1. Exposing RESTful services in Spring 5
      1. Getting started
      2. How to do it...
      3. How it works...
    2. Using the actuator REST endpoints
      1. Getting started
      2. How to do it...
      3. How it works...
    3. Building a client-side application with RestTemplate, AsyncRestTemplate and, WebClient
      1. Getting started
      2. How to do it...
      3. How it works...
    4. Configuring the Eureka server for service registration
      1. Getting started
      2. How to do it...
      3. How it works...
    5. Implementing the Eureka service discovery and client-side load balancing
      1. Getting started
      2. How to do it...
      3. How it works...
    6. Applying resiliency to client applications
      1. Getting started
      2. How to do it...
      3. How it works...
    7. Consuming endpoints using a declarative method
      1. Getting started
      2. How to do it...
      3. How it works...
    8. Using Docker for deployment
      1. Getting started
      2. How to do it...
      3. How it works...
  12. Batch and Message-Driven Processes
    1. Building synchronous batch processes
      1. Getting started
      2. How to do it...
      3. How it works...
    2. Implementing batch processes with a database
      1. Getting started
      2. How to do it...
      3. How it works...
    3. Constructing asynchronous batch processes
      1. Getting started
      2. How to do it...
      3. How it works...
    4. Building synchronous interprocess communication using AMQP
      1. Getting started
      2. How to do it...
      3. How it works...
    5. Creating asynchronous send-receive communication
      1. Getting started
      2. How to do it...
      3. How it works...
    6. Creating an event-driven asynchronous communication using AMQP
      1. Getting started
      2. How to do it...
      3. How it works...
    7. Creating stream communication with Spring Cloud Stream
      1. Getting started
      2. How to do it...
      3. How it works...
    8. Implementing batch processes using Spring Cloud Task
      1. Getting started
      2. How to do it...
      3. How it works...
  13. Other Spring 5 Features
    1. Using Hibernate 5 object-relational mapping
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Applying Hazelcast distributed caching
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Building client-server communications with WebSocket
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Implementing Reactive WebSocket communication
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Implementing asynchronous Spring Data JPA properties
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Implementing Reactive Spring Data JPA repositories
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Using Spring Data MongoDB
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Building applications for big data storage
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Building a Spring 5 application using Kotlin
      1. Getting ready
      2. How to do it...
      3. How it works...
  14. Testing Spring 5 Components
    1. Creating tests for Spring MVC components
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Building standalone controller tests
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Creating tests for DAO and service layers
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Creating tests on secured applications
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating tests using Spring Boot 2.0
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Creating tests for Spring Data JPA
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Building tests for blocking, asynchronous and reactive RESTful services
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Building tests for Kotlin components
      1. Getting ready
      2. How to do it...
      3. How it works...