Learning Spring Boot 3.0 - Third Edition

Book description

Build Java web apps without wasting any time with this third edition of the best-selling Spring Boot guide for beginners, updated and enhanced with defining features of Spring Boot 3 Purchase of the print or Kindle book includes a free eBook PDF

Key Features

  • Learn Spring Boot in a cohesive manner with this practical guide by a core Spring contributor
  • Discover popular Java developer tools such as GraalVM native images, serving up JSON, and more
  • Build secure, scalable, and manageable web applications from zero to production

Book Description

Spring Boot 3 brings more than just the powerful ability to build secure web apps on top of a rock-solid database. It delivers new options for testing, deployment, Docker support, and native images for GraalVM, along with ways to squeeze out more efficient usage of existing resources.

This third edition of the bestseller starts off by helping you build a simple app, and then shows you how to secure, test, bundle, and deploy it to production. Next, you’ll familiarize yourself with the ability to go “native” and release using GraalVM. As you advance, you’ll explore reactive programming and get a taste of scalable web controllers and data operations. The book goes into detail about GraalVM native images and deployment, teaching you how to secure your application using both routes and method-based rules and enabling you to apply the lessons you’ve learned to any problem. If you want to gain a thorough understanding of building robust applications using the core functionality of Spring Boot, then this is the book for you.

By the end of this Spring Boot book, you’ll be able to build an entire suite of web applications using Spring Boot and deploy them to any platform you need.

What you will learn

  • Create powerful, production-grade web applications with minimal fuss
  • Support multiple environments with one artifact, and add production-grade support with features
  • Find out how to tweak your Java apps through different properties
  • Enhance the security model of your apps
  • Make use of enhancing features such as native deployment and reactive programming in Spring Boot
  • Build anything from lightweight unit tests to fully running embedded web container integration tests
  • Get a glimpse of reactive programming and decide if it's the right approach for you

Who this book is for

This book is for both novices and experienced Spring developers looking to learn how to build applications without wasting time on infrastructure and other tedious details. Working knowledge of the Java programming language is assumed.

Table of contents

  1. Learning Spring Boot 3.0
  2. Third Edition
  3. Forewords
  4. Contributors
  5. About the author
  6. About the reviewer
  7. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
    9. Download a free PDF copy of this book
  8. Part 1: The Basics of Spring Boot
  9. Chapter 1: Core Features of Spring Boot
    1. Technical requirements
      1. Installing Java 17
      2. Installing a modern IDE
      3. Creating a GitHub account
      4. Finding additional support
    2. Autoconfiguring Spring beans
      1. Understanding application context
      2. Exploring autoconfiguration policies in Spring Boot
    3. Adding portfolio components using Spring Boot starters
    4. Customizing the setup with configuration properties
      1. Creating custom properties
      2. Externalizing application configuration
      3. Configuring property-based beans
    5. Managing application dependencies
    6. Summary
  10. Part 2: Creating an Application with Spring Boot
  11. Chapter 2: Creating a Web Application with Spring Boot
    1. Using start.spring.io to build apps
    2. Creating a Spring MVC web controller
    3. Using start.spring.io to augment an existing project
    4. Leveraging templates to create content
      1. Adding demo data to a template
      2. Building our app with a better design
      3. Injecting dependencies through constructor calls
      4. Changing the data through HTML forms
    5. Creating JSON-based APIs
    6. Hooking in Node.js to a Spring Boot web app
      1. Bundling JavaScript with Node.js
      2. Creating a React.js app
    7. Summary
  12. Chapter 3: Querying for Data with Spring Boot
    1. Adding Spring Data to an existing Spring Boot application
      1. Using Spring Data to easily manage data
      2. Adding Spring Data JPA to our project
    2. DTOs, entities, and POJOs, oh my!
      1. Entities
      2. DTOs
      3. POJOs
    3. Creating a Spring Data repository
    4. Using custom finders
      1. Sorting the results
      2. Limiting query results
    5. Using Query By Example to find tricky answers
    6. Using custom JPA
    7. Summary
  13. Chapter 4: Securing an Application with Spring Boot
    1. Adding Spring Security to our project
    2. Creating our own users with a custom security policy
    3. Swapping hardcoded users with a Spring Data-backed set of users
    4. Securing web routes and HTTP verbs
      1. To CSRF or not to CSRF, that is the question
    5. Securing Spring Data methods
      1. Updating our model
      2. Taking ownership of data
      3. Adding a delete button
      4. Locking down access to the owner of the data
      5. Enabling method-level security
      6. Displaying user details on the site
    6. Leveraging Google to authenticate users
      1. Pros of using OAuth
      2. Cons of using OAuth
      3. Creating a Google OAuth 2.0 application
      4. Adding OAuth Client to a Spring Boot project
      5. Invoking an OAuth2 API remotely
      6. Creating an OAuth2-powered web app
    7. Summary
  14. Chapter 5: Testing with Spring Boot
    1. Adding JUnit 5 to the application
    2. Creating tests for your domain objects
    3. Testing web controllers with MockMVC
    4. Testing data repositories with mocks
    5. Testing data repositories with embedded databases
    6. Adding Testcontainers to the application
    7. Testing data repositories with Testcontainers
    8. Testing security policies with Spring Security Test
    9. Summary
  15. Part 3: Releasing an Application with Spring Boot
  16. Chapter 6: Configuring an Application with Spring Boot
    1. Creating custom properties
    2. Creating profile-based property files
    3. Switching to YAML
    4. Setting properties with environment variables
    5. Ordering property overrides
    6. Summary
  17. Chapter 7: Releasing an Application with Spring Boot
    1. Creating an uber JAR
    2. Baking a Docker container
      1. Building the “right” type of container
    3. Releasing your application to Docker Hub
    4. Tweaking things in production
      1. Scaling with Spring Boot
    5. Summary
  18. Chapter 8: Going Native with Spring Boot
    1. What is GraalVM and why do we care?
    2. Retrofitting our application for GraalVM
    3. Running our native Spring Boot application inside GraalVM
      1. Why do we want GraalVM again?
    4. Baking a Docker container with GraalVM
      1. Spring Boot 3.0 versus Spring Boot 2.7 and Spring Native
      2. GraalVM and other libraries
    5. Summary
  19. Part 4: Scaling an Application with Spring Boot
  20. Chapter 9: Writing Reactive Web Controllers
    1. What is reactive and why do we care?
      1. Introduction to Reactive
      2. Reactive Stream details
    2. Creating a reactive Spring Boot application
    3. Serving data with a reactive GET method
    4. Consuming incoming data with a reactive POST method
      1. Scaling applications with Project Reactor
      2. Quick history on Java concurrent programming
    5. Serving a reactive template
      1. Creating a reactive web controller
      2. Crafting a Thymeleaf template
    6. Creating hypermedia reactively
    7. Summary
  21. Chapter 10: Working with Data Reactively
    1. Learning what it means to fetch data reactively
    2. Picking a reactive data store
    3. Creating a reactive data repository
    4. Trying out R2DBC
      1. Loading data with R2dbcEntityTemplate
      2. Returning data reactively to an API controller
      3. Reactively dealing with data in a template
    5. Summary
  22. Index
    1. Why subscribe?
  23. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
    3. Download a free PDF copy of this book

Product information

  • Title: Learning Spring Boot 3.0 - Third Edition
  • Author(s): Greg L. Turnquist
  • Release date: December 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781803233307