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

Learning Spring Boot 2.0 - Second Edition

Book Description

Use Spring Boot to build lightning-fast apps

About This Book

  • Get up to date with the defining characteristics of Spring Boot 2.0 in Spring Framework 5
  • Learn to perform Reactive programming with SpringBoot
  • Learn about developer tools, AMQP messaging, WebSockets, security, MongoDB data access, REST, and more

Who This Book Is For

This book is designed for both novices and experienced Spring developers. It will teach you how to override Spring Boot's opinions and frees you from the need to define complicated configurations.

What You Will Learn

  • Create powerful, production-grade applications and services with minimal fuss
  • Support multiple environments with one artifact, and add production-grade support with features
  • Find out how to tweak your apps through different properties
  • Use custom metrics to track the number of messages published and consumed
  • Enhance the security model of your apps
  • Make use of reactive programming in Spring Boot
  • Build anything from lightweight unit tests to fully running embedded web container integration tests

In Detail

Spring Boot provides a variety of features that address today's business needs along with today's scalable requirements. In this book, you will learn how to leverage powerful databases and Spring Boot's state-of-the-art WebFlux framework. This practical guide will help you get up and running with all the latest features of Spring Boot, especially the new Reactor-based toolkit.

The book starts off by helping you build a simple app, then shows you how to bundle and deploy it to the cloud. From here, we take you through reactive programming, showing you how to interact with controllers and templates and handle data access. Once you're done, you can start writing unit tests, slice tests, embedded container tests, and even autoconfiguration tests.

We go into detail about developer tools, AMQP messaging, WebSockets, security, and deployment. You will learn how to secure your application using both routes and method-based rules. By the end of the book, you'll have built a social media platform from which to apply the lessons you have learned to any problem. If you want a good understanding of building scalable applications using the core functionality of Spring Boot, this is the book for you.

Style and approach

This book takes a tutorial-based approach to teach you all you need to know to get up and running with the latest version of Spring Boot. Filled with examples, you will gain hands-on experience of every area that Spring tackles.

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. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Downloading the color images of this book
      3. Errata
      4. Piracy
      5. Questions
  2. Quick Start with Java
    1. Getting started
    2. Spring Boot starters
    3. Running a Spring Boot application
    4. Delving into Spring Boot's property support
    5. Bundling up the application as a runnable JAR file
    6. Deploying to Cloud Foundry
    7. Adding production-ready support
      1. Pinging our app for general health
      2. Metrics
    8. Summary
  3. Reactive Web with Spring Boot
    1. Creating a reactive web application with Spring Initializr
    2. Learning the tenets of reactive programming
    3. Introducing Reactor types
    4. Switching from Embedded Netty to Apache Tomcat
    5. Comparing reactive Spring WebFlux against classic Spring MVC
      1. Why is Spring doing this?
    6. Showing some Mono/Flux-based endpoints
    7. Creating a reactive ImageService
    8. Creating a reactive file controller
    9. Why use reactive programming?
    10. Interacting with a Thymeleaf template
    11. Illustrating how going from async to sync can be easy, but the opposite is not
    12. Summary
  4. Reactive Data Access with Spring Boot
    1. Getting underway with a reactive data store
    2. Solving a problem
      1. Wiring up Spring Data repositories with Spring Boot
    3. Creating a reactive repository
    4. Pulling data through a Mono/Flux and chain of operations
    5. Creating custom finders
    6. Querying by example
    7. Querying with MongoOperations
    8. Logging reactive operations
    9. Summary
  5. Testing with Spring Boot
    1. Test dependencies
    2. Unit testing
    3. Slice-based testing
      1. Testing with embedded MongoDB
      2. Testing with a real MongoDB database
    4. Testing WebFlux controllers
    5. Fully embedded Spring Boot app tests
    6. Testing your custom Spring Boot autoconfiguration
    7. Summary
  6. Developer Tools for Spring Boot Apps
    1. Using Spring Boot's DevTools for hot code reloading
    2. Using Spring Boot's autoconfiguration report
    3. Making local changes and seeing them on the target system
    4. Writing a custom health check
    5. Adding build data to /application/info
    6. Creating custom metrics
    7. Working with additional Actuator endpoints
    8. Summary
  7. AMQP Messaging with Spring Boot
    1. Getting started with RabbitMQ
      1. Installing RabbitMQ broker
      2. Launching the RabbitMQ broker
    2. Adding messaging as a new component to an existing application
    3. Creating a message producer/message consumer
      1. Displaying comments
      2. Producing comments
      3. AMQP fundamentals
    4. Adding customized metrics to track message flow
    5. Peeking at Spring Cloud Stream (with RabbitMQ)
      1. Introduction to Spring Cloud
      2. Logging with Spring Cloud Stream
    6. Summary
  8. Microservices with Spring Boot
    1. A quick primer on microservices
    2. Dynamically registering and finding services with Eureka
    3. Introducing @SpringCloudApplication
    4. Calling one microservice from another with client-side load balancing
    5. Implementing microservice circuit breakers
    6. Monitoring circuits
    7. Offloading microservice settings to a configuration server
    8. Summary
  9. WebSockets with Spring Boot
    1. Publishing saved comments to a chat service
    2. Creating a chat service to handle WebSocket traffic
      1. Brokering WebSocket messages
      2. Broadcasting saved comments
      3. Configuring WebSocket handlers
    3. Consuming WebSocket messages from the web page
    4. Moving to a fully asynchronous web client
    5. Handling AJAX calls on the server
    6. Introducing user chatting
    7. Sending user-specific messages
      1. Registering users without authentication
      2. Linking a user to a session
      3. Sending user-to-user messages
    8. Checking out the final product
    9. JSR 356 versus Spring WebFlux messaging
    10. Summary
  10. Securing Your App with Spring Boot
    1. Securing a Spring Boot application
    2. Using Spring Session
      1. Creating a Gateway API
    3. Securing the chat microservice
      1. Authentication versus authorization
    4. Sharing session details with other microservices
    5. Securing the images microservice
    6. Wiring in image ownership
      1. Authorizing methods
    7. Tailoring the UI with authorization checks
    8. Securing WebSockets
    9. Tracing calls
    10. Securing the Config Server
    11. Securing the Eureka Server
    12. Summary
  11. Taking Your App to Production with Spring Boot
    1. Profile-based sets of beans
    2. Creating configuration property beans
    3. Overriding property settings in production
      1. @ConfigurationProperties versus @Value
    4. Pushing app to Cloud Foundry and adjusting the settings
    5. Summary