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

Mastering Spring Boot 2.0

Book Description

Learn to develop, test, and deploy your Spring Boot distributed application and explore various best practices.

About This Book
  • Build and deploy your microservices architecture in the cloud
  • Build event-driven resilient systems using Hystrix and Turbine
  • Explore API management tools such as KONG and API documentation tools such as Swagger
Who This Book Is For

The book is targeted at experienced Spring and Java developers who have a basic knowledge of working with Spring Boot. The reader should be familiar with Spring Boot basics, and aware of its benefits over traditional Spring Framework-based applications.

What You Will Learn
  • Build logically structured and highly maintainable Spring Boot applications
  • Configure RESTful microservices using Spring Boot
  • Make the application production and operation-friendly with Spring Actuator
  • Build modern, high-performance distributed applications using cloud patterns
  • Manage and deploy your Spring Boot application to the cloud (AWS)
  • Monitor distributed applications using log aggregation and ELK
In Detail

Spring is one of the best frameworks on the market for developing web, enterprise, and cloud ready software. Spring Boot simplifies the building of complex software dramatically by reducing the amount of boilerplate code, and by providing production-ready features and a simple deployment model.

This book will address the challenges related to power that come with Spring Boot's great configurability and flexibility. You will understand how Spring Boot configuration works under the hood, how to overwrite default configurations, and how to use advanced techniques to prepare Spring Boot applications to work in production. This book will also introduce readers to a relatively new topic in the Spring ecosystem – cloud native patterns, reactive programming, and applications. Get up to speed with microservices with Spring Boot and Spring Cloud. Each chapter aims to solve a specific problem or teach you a useful skillset. By the end of this book, you will be proficient in building and deploying your Spring Boot application.

Style and approach

The book takes a practical, example-driven approach to teaching you all the advanced features of Spring Boot 2.0

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. Title Page
  2. Copyright and Credits
    1. Mastering Spring Boot 2.0
  3. Dedication
  4. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  5. Contributors
    1. About the author
    2. About the reviewers
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  7. Getting Started with Spring Boot 2.0
    1. Introducing Spring Boot
    2. Simplifying Spring application development using Spring Boot
    3. The essential key components of Spring Boot
      1. Spring Boot Starters
        1. Spring Boot Starter Parent POM
      2. Spring Boot auto-configuration
      3. Enabling Spring Boot auto-configuration
      4. Spring Boot CLI
      5. Spring Boot Actuator
    4. Setting up a Spring Boot workspace
      1. Setting up Spring Boot with Maven
      2. Setting up Spring Boot with Gradle
    5. Developing your first Spring Boot application
      1. Using a web interface for Spring Initializr
      2. Creating a Spring Boot project using the STS IDE
    6. Implementing the REST service
    7. New features in Spring Boot 2.0
    8. Summary
  8. Customizing Auto-Configuration in Spring Boot Application
    1. Understanding auto-configuration
      1. Learning how auto-configuration works
    2. Customizing Spring Boot
      1. Customizing using Spring Boot properties
      2. Replacing generated beans
      3. Disabling specific auto-configuration classes
      4. Changing a library's dependencies
    3. Externalizing configuration with properties
      1. Order of evaluation for overridden properties
      2. Renaming application.properties in the Spring application
    4. Externally configuring application properties
      1. Using the @EnableConfigurationProperties annotation
    5. Fine-tuning with logging
      1. Logging output
    6. Using YAML for configuration
      1. YAML for properties
      2. Multiple profiles inside a single YAML file
    7. Customizing application error pages
    8. Summary
  9. Getting Started with Spring CLI and Actuator
    1. Getting started with using Spring Boot CLI
      1. Installing the Spring Boot CLI
        1. Manually installing from a downloaded distribution
        2. Installation with SDKMAN!
        3. Installing with OSX Homebrew
          1. MacPorts installation
          2. Command-line completion
    2. Using the Initializr with the Spring Boot CLI
    3. Spring Boot Actuator – taking Application's Insights
      1. Enabling Spring Boot's Actuator in your application
      2. Analyzing the Actuator's endpoints
      3. Exposing configuration details
      4. Exposing metrics endpoints
      5. Exposing application information
      6. Shutting down your application
      7. Customizing your Actuator endpoints
        1. Enabling or disabling endpoints
        2. Changing endpoint IDs
        3. Changing the sensitivity of the Actuator's endpoints
        4. Writing custom health indicators
      8. Creating a custom endpoint
    4. Securing the Actuator endpoints
    5. The Actuator with Spring Boot 2.X
    6. Summary
  10. Getting Started with Spring Cloud and Configuration
    1. Cloud-native application architecture
      1. Microservices architecture
        1. Microservice benefits
        2. Microservice challenges
    2. Introduction to Spring Cloud
      1. Building blocks of the cloud and microservice applications
      2. Usages of Spring Cloud
    3. Configuring the Spring Cloud application
    4. Creating the configuration producer Spring Cloud Config Server
      1. Project setup and dependencies
    5. Implementing Cloud Config Server
      1. Configuring the application.properties file
      2. Creating a Git repository as configuration storage
        1. Running your configuration application
    6. Configuring multiple repositories using patterns
      1. Authentication
      2. Force-pull property
    7. Creating the configuration consumer Spring Cloud Config client
    8. Summary
  11. Spring Cloud Netflix and Service Discovery
    1. Introduction to Spring Cloud Netflix
    2. The need for Service Discovery in the microservices architecture
    3. Implementing Service Discovery – Eureka Server
      1. The Maven build configuration file
      2. The Gradle build configuration file
      3. Enabling the Eureka server as a Discovery Service server
    4. Implementing Service Discovery – Eureka clients
      1. Adding the Maven dependencies configuration
      2. The Gradle build configuration
    5. Registering a client with Eureka
      1. Consuming the REST service
      2. Using EurekaClient
        1. Using DiscoveryClient
        2. Client-side load balancing using Netflix Ribbon
      3. Using the registry-aware Spring Cloud Netflix FeignClient client
    6. Summary
  12. Building Spring Boot RESTful Microservice
    1. Microservices with Spring Boot
      1. Brief introduction to bootstrap.yml and application.yml
      2. A simple microservice example
        1. Creating a discovery service
        2. Creating a microservice (the Producer)
        3. Creating microservice consumers
          1. Load-balanced RestTemplate
    2. Brief introduction to Spring Data
      1. Apache Ignite repository
      2. Spring Data MongoDB
        1. Spring MongoDB data highlights
      3. Spring Data JPA
    3. Summary
  13. Creating API Gateway with Netflix Zuul Proxy
    1. The need for an API Gateway pattern
      1. Pros of the API Gateway pattern
      2. Cons of the API Gateway pattern
      3. API Gateway pattern components
    2. Implementing API Gateway using Netflix Zuul Proxy
      1. Including Zuul using Maven dependency
      2. Enabling the Zuul service proxy
      3. Configuring Zuul properties
      4. Adding Zuul filters
        1. Registering Zuul filters
    3. Summary
  14. Simplify HTTP API with Feign Client
    1. Declarative REST client – Feign basics
    2. Including Feign in the cloud application
      1. Overriding Feign defaults
        1. Creating Feign clients
          1. Feign inheritance support
          2. Multiple interfaces
    3. Advanced usage of the Feign client
      1. Feign logging
    4. Exception handling
    5. Custom encoders and decoders
      1. Custom encoder
      2. Custom decoder
    6. Feign and Hystrix
    7. Unit testing Feign clients
    8. Summary
  15. Building Event-Driven and Asynchronous Reactive Systems
    1. Event-driven architecture patterns
      1. Mediator topology
      2. Broker topology
    2. Introduction to reactive programming
      1. Spring Reactive
      2. ReactiveX
    3. Introduction to Command Query Responsibility Segregation
      1. Introduction to the Event Sourcing pattern
      2. Introduction to Eventual consistency
    4. Building an event-driven Reactive Asynchronous System
    5. Introducing Spring Cloud Streaming
      1. Adding Kafka to your application
        1. Installing and running Kafka
        2. Configuration properties for Kafka
        3. Service used to write to Kafka
        4. Rest API controller
        5. Listening to a Kafka topic
    6. Summary
  16. Building Resilient Systems Using Hystrix and Turbine
    1. Circuit-breaker pattern
    2. Using the Hystrix library with a reference implementation
    3. Configuring Hystrix in your application
      1. Maven dependency
      2. Enabling circuit-breaker
      3. Adding the Hystrix annotation in services
        1. Error propagation
    4. Implementing a REST controller in customer service
    5. Building and testing customer service
    6. Customizing the default configuration
    7. Hystrix Metrics Stream
    8. Implementing Hystrix Dashboard in our project
    9. Turbine dashboard
      1. Turbine stream
    10. REST consumer with Hystrix and Feign
    11. Summary
  17. Testing Spring Boot Application
    1. Test-driven development
    2. Unit testing
      1. Advantages
      2. Disadvantages
      3. Other mock libraries
    3. Integration testing
      1. Benefits of testing with Spring
      2. Activating profiles for a test class
    4. JUnit tests for the Spring Boot application
    5. Using Mockito for mocking services
    6. Postman for testing RESTful service contracts
    7. Summary
  18. Containerizing Microservice
    1. Introducing containers to the microservice architecture
      1. Virtual machines versus containers
      2. Benefits of a container-oriented approach
      3. Drawbacks of a container-oriented approach
        1. Key concepts of the containers-oriented approach
    2. Getting started with Docker
      1. Installing Docker
      2. Installing Docker on Linux
      3. Installing Docker on Windows
        1. Docker commands
        2. Container-specific commands
      4. Docker architecture
      5. Docker Engine
      6. Docker container
      7. Writing Dockerfile
    3. Dockerizing any Spring Boot application
    4. Creating a Docker image using Maven
    5. Getting started with Docker Compose
      1. Installing Docker Compose
      2. Using Docker Compose
      3. Writing a docker-compose file
      4. Orchestration using a docker-compose file
      5. Scaling containers using docker-compose and load balancing
    6. Introducing Kubernetes
    7. Summary
  19. API Management
    1. API Management
      1. Advantages of using API Management software tools
      2. API Management tools
    2. Rate limiting
      1. Implementing rate limiting
    3. Learning about KONG
      1. Microservice REST APIs with the KONG architecture
      2. Using APIs without the KONG architecture
      3. Installing KONG
      4. Using the KONG API
        1. Features of the KONG API
    4. Swagger
      1. Usage of Swagger
      2. Using Swagger in a microservice
        1. Adding a Maven dependency
        2. Configuring Swagger 2 in your project
        3. Configuring Swagger UI in your project
        4. Customizing the Swagger UI meta-configuration
          1. Filtering an API from Swagger's documentation
        5. Customizing with Swagger annotations
      3. Advantages of Swagger
    5. Summary
  20. Deploying in Cloud (AWS)
    1. Spinning up an AWS EC2 instance
    2. Microservices architecture on AWS
      1. Publishing microservices to the Docker Hub
    3. Installing Docker on AWS EC2
    4. Running microservices on AWS EC2
    5. Summary
  21. Production Ready Service Monitoring and Best Practices
    1. Monitoring containers
    2. Logging challenges for the microservices architecture
    3. Centralized logging solution for the microservices architecture
      1. Log aggregation using the ELK stack
        1. Install Elasticsearch
        2. Install Logstash
        3. Install Kibana
      2. Requesting tracing using Sleuth
      3. Requesting tracing with Zipkin
        1. Adding the Zipkin server to your machine
    4. Summary
  22. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think