Hands-on Application Development using Spring Boot
eBook - ePub

Hands-on Application Development using Spring Boot

Building Modern Cloud Native Applications by Learning RESTFul API, Microservices, CRUD Operations, Unit Testing, and Deployment

  1. English
  2. ePUB (mobile friendly)
  3. Available on iOS & Android
eBook - ePub

Hands-on Application Development using Spring Boot

Building Modern Cloud Native Applications by Learning RESTFul API, Microservices, CRUD Operations, Unit Testing, and Deployment

About this book

A pragmatic guide for Java developers to help build Microservices and Cloud Apps using Spring Boot.

Key Features
? Develops microservices from start to finish using the Spring Boot Framework.
? Creates cloud-native applications using Spring Boot's production-ready features.
? Covers the API gateway, unit testing, cloud deployments, and managing high-traffic applications.

Description
Spring is an excellent framework for developing both web and cloud-native applications. This book on application development using Spring Boot simplifies the process of writing boilerplate code for complex software. It allows developers to concentrate on the application's concept rather than on the internal Java configuration.This book will guide you on how to make the best use of the strength that Spring Boot provides. You'll gain an understanding of how Spring Boot configuration works in conjunction with application development, including auto-configuration and overriding default configurations. You will learn to develop scalable, dependable microservices to accelerate the development lifecycle of a cloud-based application. Each chapter will walk you through the features of Spring Boot as a Software Development Framework, such as performing Create, Read, Update, and Delete (CRUD) operations on a database and securing web services with appropriate logging.By the end of this book, you will develop, test, and deploy applications ready for production and how to establish them as cloud-based applications. The readers will also gain the expertise of writing unit and integration test cases.

What you will learn
? Get to know Spring Boot and all its capabilities.
? Build start-to-end production-ready applications.
? Explore the API Gateway and practice how to run request routing.
? Learn API doc tools like Swagger and host your apps on Cloud.
? Practice how to balance the application's load when the system is under high traffic.
? Learn to write unit tests and integration tests for bug-free coding.

Who this book is for
This book is for Java developers who want to quickly develop, test, and deploy production-ready applications. This book will also appeal to cloud-native application developers and cloud engineers. No prior Spring Boot knowledge is required as the basics are covered in the book.

Table of Contents
1. Getting Started with Spring Boot
2. Developing Your First Spring Boot Application
3. Spring Boot Starter Dependencies and Auto-Configuration
4. Spring Boot Annotations
5. Working with Spring Data JPA and Caching
6. Building RESTFul Microservices
7. Securing a Web Application
8. Building Resilient System
9. Logging
10. Working with the Swagger API Management Tool
11. Testing a Spring Boot Application
12. Deploying a Spring Boot Application

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Hands-on Application Development using Spring Boot by Shagun Bakliwal in PDF and/or ePUB format, as well as other popular books in Computer Science & Systems Architecture. We have over one million books available in our catalogue for you to explore.

CHAPTER 1

Getting Started with Spring Boot

As the web application development has changed from Java Server Pages (JSPs), Servlets to Spring, many problems of the boiler plate code have reduced. Spring has really reduced the boilerplate code to an extent. The Spring team has developed Spring Boot on the top of the Spring framework that eliminated boilerplate configurations required for Spring applications. This chapter will introduce you to the Spring Boot Framework with the latest version 2.4.3. It will cover the basics of setting up the Spring Boot workspace with tools like JDK 8, Spring Tool Suite (STS), Spring Initializr, and Apache Maven and Gradle as build tools.

Structure

In this chapter, we will discuss the following topics:
  • Introduction to Spring Boot
  • Features of Spring Boot
  • Advantages of Spring Boot
  • Breaking the monolithic way of developing software
  • When to start using microservices?
  • When not to start using microservices?
  • System requirements
  • Setting up the environment
  • The 12-factor app
  • Spring Initializr

Objectives

After studying this unit, you should be able to understand the concept of Spring Boot. You can set up your development environment and learn the 12-factor app that an application should have.

Introduction to Spring Boot

On October 17, 2012, Mike Youngstrom opened a JIRA ticket with the Spring framework team asking for the support for container less web application architectures. As the developers would be more interested in adopting a simpler framework, there should be a mechanism that would allow the developers not to remember both configurations for the Spring model as well as the servlet container on which they are executing their application. There were few items within the older architecture of Spring core that was configured in an inconsistent non-unified way that the developers have to first learn the servlet container on which they are going to deploy in addition to the Spring’s own configuration model.
He proposed an idea for having the servlet container and related tools as a part of the Spring component by embedding and unifying the configuration of those common web container services with the Spring container that can be bootstrapped from the main() method.
This issue was addressed by Phil Webb and from there the Spring Boot started evolving in 2013. On April 1, 2014, the first Spring Boot 1.0 Globally Available (GA) was released which addressed the preceding concern in addition to the issues.
Spring Boot is now an open-source Java-based framework used to create standalone microservices with production-ready features. It is heavily maintained by the Pivotal Team. Microservices is an architectural design that creates scalable, loosely coupled, and testable applications which have a single function module with well-defined interfaces. The microservices hence created by using Spring Boot can be owned and maintained by a small team; unlike it used to be while creating APIs by older technologies like Java web services that required a team of a larger size. This microservice design is adapted by many enterprises in recent years as they look to have their software development delivery in the Agile manner where they can continuously develop, test, and deliver.

Features of Spring Boot

Why the Spring team developed Spring Boot? How is it beneficial for developers to build their application on Spring Boot and not Spring? How are configurations managed? All features of Spring Boot would be explained in this and upcoming chapters. Few of them are listed as follows:
  • Faster way of developing applications by reducing the boilerplate configurations.
  • Loosely coupled dependencies.
  • Starter packs available as part of dependency for simplifying builds and configuration.
  • Creating production-ready microservices with actuator health endpoints such as health, httptrace, mappings, metrics, info, configprops, env, and so on.
  • Embedded container server support. By default, Tomcat is used.
  • Auto-configuration for dependencies; once the dependency is loaded into the class path, Spring Boot manages the class instantiations, when needed.
  • Externalized configurations with the help of .properties and .yml files and Spring Cloud Config.
  • Live reload for the application during the development phase.
  • Ability to exclude/change the dependency version before deployment.

Advantages of Spring Boot

Spring Boot helps you to create stand-alone Spring-based applications with production-ready features that you can execute on the local workspace and the cloud platform which has the Java Virtual Machine (JVM) installed. By using Spring Boot as the development platform, you can get started with the creation of an application with minimum code setup with less development time, so that the focus will be in contract with the features that you want to imply in the application. This allows the developer to focus on the idea that evolves during the initial phase of the requirement and then it is the magic of Spring Boot that helps you to bootstrap your application, its external dependencies on the resources like accessing the database and managing the external calls to other applications that consume the data in the prescribed format. Mostly, Spring Boot applications need less Spring configuration.
After you build your Spring Boot application, it can be executed by java –jar <jar name> just like any other Java project that builds a jar file. The Spring Boot application can also be started by running the mvn spring-boot:run command on the root directory which contains the src folder.

Breaking the monolithic way of developing software

Since years the software development used to happen in a monolithic architecture. The developer or the business analyst or even the product owner of the software receives a big requirement at once and then after getting the details of the requirements, the team starts to work on. This leads to the waterfall model of developing a software which is good to release a Minimal Viable Product (MVP) that is a single release to showcase about what the product is. This single release is created in a single application containing all codes to resolve the user problem. Problem arises when the requirements are portrayed in such a way that the code already developed is duplicated to fulfill another requirement, that is, chunks of code can be repeated which leads to bad quality of code.
Now imagine for that requirement, all we need to repeat all sorts of regression and stress testing which was already done previously before releasing the product. Why should all codes be tested even if that single enhancement may not be related to test the whole application?
Since then, business capabilities are delivered using microservices. Now, selecting the microservice architecture over the monolithic architecture can have many reasons and may not be limited to the features of microservices as follows:
  • Each service can have a single functionality, single data repository.
  • Each service is in...

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Dedication Page
  5. About the Author
  6. About the Reviewer
  7. Acknowledgements
  8. Preface
  9. Errata
  10. Table of Contents
  11. 1. Getting Started with Spring Boot
  12. 2. Developing Your First Spring Boot Application
  13. 3. Spring Boot Starter Dependencies and Auto-Configuration
  14. 4. Spring Boot Annotations
  15. 5. Working with Spring Data JPA and Caching
  16. 6. Building RESTFul Microservices
  17. 7. Securing a Web Application
  18. 8. Building Resilient System
  19. 9. Logging
  20. 10. Working with the Swagger API Management Tool
  21. 11. Testing a Spring Boot Application
  22. 12. Deploying a Spring Boot Application
  23. Index