Spring 5.0 Projects

Book Description

Discover the latest features of Spring framework by building robust, fast, and reactive web applications

Key Features

  • Take advantage of all the features of Spring 5.0 with third party tools to build a robust back end
  • Secure Spring based web application using Spring Security framework with LDAP and OAuth protocol
  • Develop robust and scalable microservice based applications on Spring Cloud, using Spring Boot

Book Description

Spring makes it easy to create RESTful applications, merge with social services, communicate with modern databases, secure your system, and make your code modular and easy to test. With the arrival of Spring Boot, developers can really focus on the code and deliver great value, with minimal contour.

This book will show you how to build various projects in Spring 5.0, using its features and third party tools. We'll start by creating a web application using Spring MVC, Spring Data, the World Bank API for some statistics on different countries, and MySQL database. Moving ahead, you'll build a RESTful web services application using Spring WebFlux framework. You'll be then taken through creating a Spring Boot-based simple blog management system, which uses Elasticsearch as the data store. Then, you'll use Spring Security with the LDAP libraries for authenticating users and create a central authentication and authorization server using OAuth 2 protocol. Further, you'll understand how to create Spring Boot-based monolithic application using JHipster. Toward the end, we'll create an online book store with microservice architecture using Spring Cloud and Net?ix OSS components, and a task management system using Spring and Kotlin.

By the end of the book, you'll be able to create coherent and ?exible real-time web applications using Spring Framework.

What you will learn

  • Build Spring based application using Bootstrap template and JQuery
  • Understand the Spring WebFlux framework and how it uses Reactor library
  • Interact with Elasticsearch for indexing, querying, and aggregating data
  • Create a simple monolithic application using JHipster
  • Use Spring Security and Spring Security LDAP and OAuth libraries for Authentication
  • Develop a microservice-based application with Spring Cloud and Netflix
  • Work on Spring Framework with Kotlin

Who this book is for

This book is for competent Spring developers who wish to understand how to develop complex yet flexible applications with Spring. You must have a good knowledge of Java programming and be familiar with the basics of Spring.

Publisher Resources

Download Example Code

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Spring 5.0 Projects
  3. About Packt
    1. Why subscribe?
    2. Packt.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. 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. Download the color images
      3. Code in Action
      4. Conventions used
    4. Get in touch
      1. Reviews
  6. Creating an Application to List World Countries with their GDP
    1. Technical requirements
    2. Introduction to the application
    3. Understanding the database structure
    4. Understanding the World Bank API
    5. Designing the wireframes of application screens
      1. Country listing page
      2. Country detail page
      3. Country edit page
      4. Add a new city and language
    6. Creating an empty application
    7. Defining the model classes
      1. Using Hibernate Validator to add validations
    8. Defining the data access layer – Spring JDBC Template
      1. Defining the JDBC connection properties
      2. Setting up the test environment
      3. Defining the RowMapper
      4. Designing the CountryDAO 
      5. Designing the CityDAO
      6. Designing the CountryLanguageDAO
      7. Designing the client for World Bank API
    9. Defining the API controllers
      1. Enabling Web MVC using @EnableWebMvc
      2. Configuration to deploy to Tomcat without web.xml
      3. Defining the RESTful API controller for country resource
      4. Defining the RESTful API controller for city resource
      5. Defining the RESTful API controller for country language resource
    10. Deploying to Tomcat
    11. Defining the view controller
    12. Defining the view templates
      1. Configuring a Thymeleaf template engine
      2. Managing static resources
      3. Creating the base template
    13. Logging configuration
    14. Running the application
    15. Summary
  7. Building a Reactive Web Application
    1. Technical requirements
    2. Reactive system
    3. Reactive Programming
      1. Basics of Reactive Programming
        1. Backpressure
      2. Benefits of Reactive Programming
      3. Reactive Programming techniques
    4. Reactive Programming in Java
      1. Reactive Streams
        1. Reactive Streams specifications
          1. Publisher rules
          2. Subscriber rules
          3. Subscription rules
          4. Processor rules
          5. Reactive Streams TCK
      2. RxJava
        1. Anatomy of RxJava 
        2. Observer event calls
        3. Observable for iterators
        4. Custom Observers
        5. Observable types
          1. Cold Observable
          2. Hot Observable
        6. Other ways to get Observable
        7. Operators
      3. Project Reactor
        1. Reactor features
          1. Handling data stream with high volume
          2. Push-pull mechanism
          3. Handling concurrency independently 
          4. Operators
        2. Reactor sub-projects
        3. Reactor types
        4. Reactor in action 
        5. Types of subscribers
        6. Custom subscribers
        7. Reactor lifecycle methods
      4. Ratpack
      5. Akka stream
      6. Vert.x
    5. Reactive support in Spring Framework
      1. Spring WebFlux
        1. Spring MVC versus Spring WebFlux
        2. Reactive span across Spring modules
    6. Spring WebFlux application
      1. MongoDB installation
        1. MongoDB data structure
      2. Creating a Spring Data repository
      3. WebFlux programming models
        1. Annotated controller
        2. Functional endpoint
          1. Artifacts required in functional-style Reactive Programming 
          2. Prerequisite for a functional approach in Spring WebFlux
          3. Defining routers and handlers
          4. Combining handler and router
          5. Composite routers
      4. WebSocket support
    7. Summary
  8. Blogpress - A Simple Blog Management System
    1. Technical requirements
    2. Application overview
    3. Project skeleton with Spring Boot
      1. Configuring IDE Spring Tool Suite
    4. Spring Model-View-Controller web flow
    5. Presentation layer with Thymeleaf
      1. How Thymeleaf works
      2. Dialects, processors, and expression objects
      3. Why Thymeleaf is a natural template
    6. Making the application secure with Spring Security
      1. Excluding auto-configuration
      2. Substituting auto-configuration
    7. Storing data with Elasticsearch
      1. Artifacts
        1. Documents
        2. Indexes
        3. Clusters and nodes
        4. Shards and replicas
      2. Interacting with Elasticsearch
      3. Installation
      4. Elasticsearch RESTful API
        1. Creating an index – students
        2. Creating a document type – student
        3. Adding a document (student data)
        4. Reading a document (student data)
        5. Updating a document (student data)
        6. Deleting a document (student data)
        7. Searching a query
      5. Creating index and document types for Blogpress
      6. Elasticsearch integration with Spring Data
        1. Spring Data Elasticsearch model class
        2. Connecting Elasticsearch with Spring Data
        3. CRUD operations in Elasticsearch with Spring Data
          1. Adding blog data
          2. Reading blog data
          3. Searching blog data
          4. Adding comment data with Elasticsearch aggregation
          5. Reading comment data with Elasticsearch aggregation
          6. Updating and deleting comment data with Elasticsearch
    8. Displaying data with RESTful web services in Spring
    9. Building a UI with the Mustache template
    10. Summary
  9. Building a Central Authentication Server
    1. Technical requirements
    2. LDAP
      1. What is LDAP?
      2. Configuring Apache DS as an LDAP server
      3. Example DIT structures
      4. Apache DS partitions
      5. The LDAP structure
    3. Spring Security integration with LDAP
      1. Creating a web application with Spring Boot
      2. Managing LDAP users with Spring Data
        1. Spring Data models
        2. The Spring Data repository for LDAP
        3. Performing CRUD operations with LdapTemplate
          1. Initializing LdapTemplate
          2. Using LdapTemplate to perform CRUD operations
    4. LDAP authorization with Spring Security
      1. Creating roles in the LDAP server
      2. Importing role information to perform authorization
    5. OAuth
      1. OAuth roles
      2. Grant types
        1. Authorization code
        2. Implicit
        3. Resource Owner Password Credentials
        4. Client Credentials
      3. Which grant type should be used?
    6. Spring Security integration with OAuth
      1. Application registration
      2. Changes in the Spring Boot application
        1. The default OAuth configuration
        2. OAuth with a custom login page
        3. Dual authentication with OAuth and LDAP
      3. OAuth authorization with a custom authorization server
        1. Authorization server configuration
        2. Resource server configuration
        3. Method-level resource permissions
    7. Summary
  10. An Application to View Countries and their GDP using JHipster
    1. Technical requirements
    2. Introducing JHipster
    3. Installing JHipster
    4. Creating an application
      1. Project structure
    5. Entity creation
      1. Adding an entity with the CLI
      2. Modeling the entity
        1. Modeling with UML
        2. Modeling with JHipster Domain Language studio
          1. Generating an entity using a model
    6. Showing the national gross domestic product
      1. Application and entity creation
      2. Handling enumeration data with a database in JHipster 
      3. Filter provision in service, persistence, and the REST controller layer
        1. The persistence layer
        2. The service layer
        3. The REST controller layer
        4. Adding a filter option to existing entities
      4. Developing custom screens
        1. The search country screen
          1. Creating an Angular service
          2. Creating the Angular router
          3. Angular modules
          4. Creating an Angular component to show the country list
          5. Angular template to show the country list
        2. Showing the GDP screen
          1. An Angular component to show country GDP
          2. Angular template to show country GDP
        3. Hooking the GDP module into AppModule
      5. Updating navigation
    7. Other JHipster features
      1. IDE support
      2. Setting screens out of the box
        1. Home and login screens
        2. Account management
        3. Administration
          1. User management
          2. Metrics
          3. Health
          4. Configuration
          5. Audit
          6. Logs
          7. API
      3. Maintaining code quality 
      4. Microservice support
      5. Docker support
      6. Profile management
      7. Live reload
      8. Testing support
      9. Upgrading JHipster
      10. Continuous integration support
      11. Community support and documentation
      12. The JHipster Marketplace
    8. Summary
  11. Creating an Online Bookstore
    1. Technical requirements
    2. Microservices introduction
      1. Microservice architecture 
      2. Microservice principles
        1. High cohesion with a single responsibility
        2. Service autonomy
        3. Loose coupling
        4. Hide implementation through encapsulation
        5. Domain-driven design
      3. Microservice characteristics
      4. Microservices with Spring Cloud
        1. Configuration management
        2. Service discovery
        3. Circuit breakers
        4. Routing
        5. Spring Cloud Security
        6. Distributed tracing service
        7. Spring Cloud Stream
    3. Developing an online bookstore application
      1. Application architecture
      2. Database design
        1. Single monolithic database for all microservices
        2. Separate service to handle database interaction
        3. Each microservice has its own database
          1. User schema
          2. Order schema
          3. Catalog schema
          4. Inventory schema
      3. Creating microservices with Spring Boot
        1. Adding microservice-specific capabilities
      4. Develop a service discovery server
      5. Designing an API gateway
        1. Setting up Zuul as an API gateway
      6. Designing the UI
        1. Monolithic front
        2. Micro front
        3. Composite front
      7. Other Spring Cloud and Netflix OSS components
        1. Dynamic configuration in Spring Cloud
          1. Step 1 – creating a Spring Boot service for the configuration server
          2. Step 2 – configuring Spring Cloud Config with a Git repository
          3. Step 3 – making each microservice Spring Cloud Config-aware using the Spring Cloud Config Client component
        2. Making RESTful calls across microservices with Feign 
        3. Load balancing with Ribbon
          1. Configuring Ribbon without Eureka
          2. Configuring Ribbon with Eureka
          3. Load balancing using RestTemplate
      8. Configuring the API gateway
      9. Securing an application
    4. Summary
  12. Task Management System Using Spring and Kotlin
    1. Technical requirements
    2. Introducing Kotlin 
      1. Interoperability 
      2. Concise yet powerful 
      3. Safety feature
      4. IDE Support
    3. Kotlin features
      1. The concept of a function
        1. Function as an expression
        2. Default function arguments
        3. Extension functions
        4. Lambda expression or function literal
          1. Passing lambda to another function
          2. Returning a function from another function
      2. Null safety
      3. Data classes
      4. Interoperability
        1. Calling the Kotlin code from Java
        2. Calling Java code from Kotlin 
      5. Smart casts
      6. Operator overloading
      7. Kotlin versus Java
    4. Spring supports for Kotlin
    5. Developing an application – Task Management System
      1. Creating a Spring Boot project with Kotlin
      2. DB design 
        1. Entity classes
          1. Users
          2. Role
          3. Task
          4. Comments
      3. Spring Security
        1. Query approach
        2. UserDetailsService approach
      4. Defining the Spring MVC controller
        1. Showing the control page
        2. Showing the login page
        3. Showing the add new task page
        4. Showing the edit task page
        5. Adding a new task
        6. Updating a task
        7. Adding a task comment
        8. Getting all users
        9. Showing a task list
        10. Viewing a task
        11. Deleting a task
      5. REST call in Kotlin
        1. Validation
        2. User registration
    6. Summary
  13. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product Information

  • Title: Spring 5.0 Projects
  • Author(s): Nilang Patel
  • Release date: February 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781788390415