You are previewing Spring Boot Cookbook.
O'Reilly logo
Spring Boot Cookbook

Book Description

Over 35 recipes to help you build, test, and run Spring applications using Spring Boot

About This Book

  • Learn to create different types of Spring Boot applications, configure behavior, and add custom components

  • Become more efficient in testing, deploying, and monitoring Spring Boot based applications

  • This is a practical guide that will help Spring developers to develop and deploy applications using Spring Boot

  • Who This Book Is For

    If you are a Spring Developer who has good knowledge level and understanding of Spring Boot and application development and now want to learn efficient Spring Boot development techniques in order to make the existing development process more efficient, then this book is for you.

    What You Will Learn

  • Create Spring Boot applications from scratch

  • Configure and tune web applications and containers

  • Create custom Spring Boot auto-configurations and starters

  • Use Spring Boot Test framework with JUnit, Cucumber, and Spock

  • Configure and tune web applications and containers

  • Deploy Spring Boot as self-starting executables and Docker containers

  • Monitor data using DropWizard, Graphite, and Dashing

  • In Detail

    Spring Boot is Spring's convention-over-configuration solution. This feature makes it easy to create Spring applications and services with absolute minimum fuss. Spring Boot has the great ability to be customized and enhanced, and is specifically designed to simplify development of a new Spring application.

    This book will provide many detailed insights about the inner workings of Spring Boot, as well as tips and recipes to integrate the third-party frameworks and components needed to build complex enterprise-scale applications.

    The book starts with an overview of the important and useful Spring Boot starters that are included in the framework, and teaches you to create and add custom Servlet Filters, Interceptors, Converters, Formatters, and PropertyEditors to a Spring Boot web application. Next it will cover configuring custom routing rules and patterns, adding additional static asset paths, and adding and modifying servlet container connectors and other properties such as enabling SSL.

    Moving on, the book will teach you how to create custom Spring Boot Starters, and explore different techniques to test Spring Boot applications. Next, the book will show you examples of configuring your build to produce Docker images and self-executing binary files for Linux/OSX environments.

    Finally, the book will teach you how to create custom health indicators, and access monitoring data via HTTP and JMX.

    Style and approach

    This book is a cohesive collection of recipes that provide developers with a set of connected guidelines on how to build, configure, and customize their application, starting from the design and development stages, all the way through testing, deployment, and production monitoring.

    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 files e-mailed directly to you.

    Table of Contents

    1. Spring Boot Cookbook
      1. Table of Contents
      2. Spring Boot Cookbook
      3. Credits
      4. About the Author
      5. Acknowledgment
      6. About the Reviewers
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      8. 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. Errata
          3. Piracy
          4. Questions
      9. 1. Getting Started with Spring Boot
        1. Introduction
        2. Using a Spring Boot template and starters
          1. How to do it…
          2. How it works…
        3. Creating a simple application
          1. How to do it…
          2. How it works…
        4. Launching an application using Gradle
          1. How to do it…
          2. How it works…
        5. Using the command-line runners
          1. How to do it…
          2. How it works…
        6. Setting up a database connection
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Setting up a data repository service
          1. How to do it…
          2. How it works…
        8. Scheduling executors
          1. Getting ready
          2. How to do it…
          3. How it works…
      10. 2. Configuring Web Applications
        1. Creating a basic RESTful application
          1. How to do it…
          2. How it works…
        2. Creating a Spring Data REST service
          1. How to do it…
          2. How it works…
        3. Configuring custom servlet filters
          1. How to do it…
          2. How it works…
        4. Configuring custom interceptors
          1. How to do it…
          2. How it works…
        5. Configuring custom HttpMessageConverters
          1. How to do it…
          2. How it works…
        6. Configuring custom PropertyEditors
          1. How to do it…
          2. How it works…
        7. Configuring custom type Formatters
          1. How to do it…
          2. How it works…
      11. 3. Web Framework Behavior Tuning
        1. Introduction
        2. Configuring route matching patterns
          1. How to do it…
          2. How it works…
        3. Configuring custom static path mappings
          1. How to do it…
          2. How it works…
        4. Tuning Tomcat via EmbeddedServletContainerCustomizer
          1. How to do it…
          2. How it works…
        5. Choosing embedded servlet containers
          1. How to do it…
          2. How it works…
        6. Adding custom connectors
          1. Getting ready
          2. How to do it…
          3. How it works…
      12. 4. Writing Custom Spring Boot Starters
        1. Introduction
        2. Understanding Spring Boot autoconfiguration
          1. How to do it…
          2. How it works…
        3. Creating a custom Spring Boot autoconfiguration starter
          1. How to do it…
          2. How it works…
        4. Configuring custom conditional bean instantiations
          1. How to do it…
          2. How it works…
        5. Using custom @Enable* annotations to toggle configurations
          1. How to do it…
          2. How it works…
      13. 5. Application Testing
        1. Introduction
        2. Creating tests for Spring MVC Controllers
          1. How to do it…
          2. How it works…
        3. Automatically configuring the database schema and populating it with data
          1. How to do it…
          2. How it works…
            1. Initializing the database with Spring JPA and Hibernate
            2. Initializing the database with Spring JDBC
        4. Creating tests using in-memory database with data fixtures
          1. How to do it…
          2. How it works…
        5. Creating tests using Mockito to mock DB
          1. How to do it…
          2. How it works…
        6. Writing tests using Cucumber
          1. How to do it…
          2. How it works…
        7. Writing tests using Spock
          1. How to do it…
          2. How it works…
      14. 6. Application Packaging and Deployment
        1. Introduction
        2. Creating a Spring Boot executable JAR
          1. How to do it…
          2. How it works…
        3. Creating Docker images
          1. How to do it…
          2. How it works…
        4. Building self-executing binaries
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Spring Boot environment config hierarchy and precedence
          1. How to do it…
          2. How it works…
        6. Externalizing environmental config using property files
          1. How to do it…
          2. How it works…
        7. Externalizing environmental config using environment variables
          1. How to do it…
          2. How it works…
        8. Externalizing environmental config using Java system properties
          1. How to do it…
          2. How it works…
        9. Setting up Consul
          1. How to do it…
          2. How it works…
        10. Externalizing environmental config using Consul and envconsul
          1. Getting ready
          2. How to do it…
          3. How it works…
      15. 7. Health Monitoring and Data Visualization
        1. Introduction
        2. Writing custom health indicators
          1. How to do it…
          2. How it works…
        3. Emitting metrics
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Monitoring Spring Boot via JMX
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Management of Spring Boot via CRaSH and writing custom remote shell commands
          1. How to do it…
          2. How it works…
        6. Integrating Codahale/Dropwizard metrics with Graphite
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Integrating Codahale/Dropwizard metrics with Dashing
          1. Getting ready
          2. How to do it…
          3. How it works…
      16. Index