Spring Boot 2: How To Get Started and Build a Microservice - Third Edition
By Jens Boje
5/5
()
About this ebook
From Zero Spring Experience to Building Your First Microservice with Spring Boot 2
Learn to build your first microservice with Spring Boot. Together we will write a production-ready microservice with a REST API in just a few hours. All starting from having zero experience with Spring at all.
Revised and extended 3rd edition
Update: Using Spring Boot 2.1.8.RELEASE version.
Our guides give you brief lessons on a single topic to get you started in no time. We leave the fluff out so you can focus and learn better and faster. Stop wasting hours of your life watching video courses or reading boring compendiums. Use our guide and save your precious time and be way ahead of your competitors on that next big project.
We build a real application (less than 850 lines of code though) using a standard Maven project structure together, and I will explain you the steps and libraries involved on the go. You must know Java.
You learn best by coding. The way I love learning too. And not by reading fluffy compendiums or watching 10 hours and more of videos. Sure, you can do that, but any developer following my guide will be way ahead of you before you are even halfway through that video course.
What you will build:
We build a Microservice for storing comments and providing a REST interface for interacting with the data. The sample application is modeled after a real production application to guide you through building your first Spring Boot application.
What you will learn:
What problem the Spring Framework actually solves
The basics of the Spring Framework aka Core
How to build a microservice with Spring Boot 2
How to work with a relational database using the Spring Data JPA Framework
How to write the REST API using Spring MVC
How to create a service layer and integrate a legacy library using its own Spring ApplicationContext in an XML file
How to test the application
A simple way to secure your application
How to use monitoring and health check out of the box with Spring Boot
How to deploy your application
How to navigate in the project with Maven
You must have experience with Java as we are not covering Java basics. Everything else we use is covered in the guide.
If you have questions, do not hesitate to contact me using the email address at the end of the book. I'll answer your questions and improve the book with your feedback. Promised!
Jens Boje
Father, Software Developer, Entrepreneur
Read more from Jens Boje
Find Your Why: How I Found My Inner Drive and How You Can Too Rating: 0 out of 5 stars0 ratings
Related to Spring Boot 2
Titles in the series (3)
Spring Boot 2: How To Get Started and Build a Microservice - Third Edition Rating: 5 out of 5 stars5/5Spring Boot and Single-Page Applications: Securing Your API with a Single-Page Application Frontend - Second Edition Rating: 0 out of 5 stars0 ratingsSpring Boot Intermediate Microservices: Resilient Microservices with Spring Boot 2 and Spring Cloud Rating: 0 out of 5 stars0 ratings
Related ebooks
Spring Boot and Single-Page Applications: Securing Your API with a Single-Page Application Frontend - Second Edition Rating: 0 out of 5 stars0 ratingsSpring Boot Cookbook Rating: 0 out of 5 stars0 ratingsSpring and Spring Boot Interview Questions and Answers. Tech interviewer’s notes Rating: 5 out of 5 stars5/5Spring Boot Intermediate Microservices: Resilient Microservices with Spring Boot 2 and Spring Cloud Rating: 0 out of 5 stars0 ratingsSpring Boot in Action Rating: 0 out of 5 stars0 ratingsMastering Spring 5.0 Rating: 5 out of 5 stars5/5Java 9 Concurrency Cookbook - Second Edition Rating: 0 out of 5 stars0 ratingsSpring Start Here: Learn what you need and learn it well Rating: 0 out of 5 stars0 ratingsHacking with Spring Boot 2.4: Classic Edition: Hacking with Spring Boot, #2 Rating: 0 out of 5 stars0 ratingsReact Deep Dive Rating: 5 out of 5 stars5/5JavaScript: Tips and Tricks to Programming Code with Javascript: JavaScript Computer Programming, #2 Rating: 0 out of 5 stars0 ratingsAngular Essentials: The Essential Guide to Learn Angular Rating: 0 out of 5 stars0 ratingsBuilding a RESTful Web Service with Spring Rating: 5 out of 5 stars5/5Mastering Unit Testing Using Mockito and JUnit Rating: 0 out of 5 stars0 ratingsRESTful Java Web Services Interview Questions You'll Most Likely Be Asked: Second Edition Rating: 0 out of 5 stars0 ratingsSpring Essentials Rating: 0 out of 5 stars0 ratingsSpring MVC: Designing Real-World Web Applications Rating: 0 out of 5 stars0 ratingsSpring Data Rating: 0 out of 5 stars0 ratingsMastering Hibernate Rating: 0 out of 5 stars0 ratingsJava Hibernate Cookbook Rating: 0 out of 5 stars0 ratingsBuilding Scalable Apps with Redis and Node.js Rating: 0 out of 5 stars0 ratingsSpring MVC Beginner’s Guide Rating: 2 out of 5 stars2/5
Programming For You
Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Java for Beginners: A Crash Course to Learn Java Programming in 1 Week Rating: 5 out of 5 stars5/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Python Machine Learning By Example Rating: 4 out of 5 stars4/5101 Amazing Nintendo NES Facts: Includes facts about the Famicom Rating: 4 out of 5 stars4/5Pokemon Go: Guide + 20 Tips and Tricks You Must Read Hints, Tricks, Tips, Secrets, Android, iOS Rating: 5 out of 5 stars5/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Modern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 Standards Rating: 0 out of 5 stars0 ratingsPython Projects for Beginners: A Ten-Week Bootcamp Approach to Python Programming Rating: 0 out of 5 stars0 ratings
Reviews for Spring Boot 2
1 rating1 review
- Rating: 5 out of 5 stars5/5My First ever technical book which kept me engaged throughout and constantly learning.
The best part of this book is Author Jens covered everything in and around SpringBoot.
Every Developer should read this for a quick bootstrap of SpringBoot!
Definitely recommended!
Book preview
Spring Boot 2 - Jens Boje
README
Learning to build applications and especially APIs with Spring and Spring Boot is exciting. At the same time, it is freighting when you stay at the bottom of Mt. Spring.
Spring Boot makes it much easier than it was with Spring alone in the past. However, it also hides much of the complexity involved in its magic, which brings in new complexity and might leave you confused sometimes.
Be assured that this is totally normal and everyone went through this phase. When you hike up, it gets easier as you will gain a solid understanding and control of the complexity involved and you can build frictionless applications with it.
I know I felt this way when I first started out with Spring, and there was no Spring Boot at that time. But, that’s temporary, and it gets much better over time. When I walked up Mt. Spring a bit, it already got easier. And it wasn’t just me, I noticed the same with friends and co-workers.
In the book, I reduce the complexity and focus on small, manageable parts, so you get productive quickly. It is the same approach I use successfully in my workshops or when helping co-workers in-person. Unlike in-person interaction, I’m not with you to see you when you progress through the book. Therefore, I can’t notice when you have a question so I can rephrase and explain it differently. Nonetheless, you are not alone, you can ask me, and I will help you get unstuck. Promise– just email me.
Introduction
This book’s approach differs from that of other programming books that you may have encountered. I believe that the best way to learn a new framework or language is to build applications using it. I also assume that you have some experience with Java, Maven, and the IDE of your choice.
The application for the book is modeled after a real production application serving thousands of requests and running smoothly since its first deployment. The sample application follows the same implementation approach but leaves out certain complexities which are not needed for learning to build a microservice with Spring Boot.
The original application stores binary files and certain metadata, like product references, width, and height of images, file size, for covers and other marketing materials of books. The application is integrated into a large infrastructure and offers all of its services GUI-less. However, for the sample application, we will do something simpler for learning and are going to develop a commenting system.
What will the application do:
store comments for products or pages
check comments for spam and flag them accordingly
provide a restful interface to add, delete and retrieve the comments
What we will build in this book:
a simple SpamDetector for learning to use Spring Core
a persistence tier using Spring Data JPA
a service Layer using our previously build storage and integrating our SpamDetector module for spam detection
a RESTful API using Spring MVC
We will test our microservice, make it production-ready with Spring Boots’ features, and finally deploy it as a standalone microservice.
The full source code of this book’s sample application is available on GitHub: Link
The project uses a Multi Module Maven layout. Build and run instructions are in the repository.
I also added all external reference to a private resource page for your convenience.
If you have any questions, do not hesitate to contact me at the email address found in the last chapter.
You Don’t Need a Specific IDE
I wrote the book intentionally without using a particular IDE in mind for various reasons.
You can build Spring Boot applications with any IDE or with plain Texteditor and Maven
I might not use your loved IDE and thus either force you to use an IDE you do not know or like, which is terrible for learning. You don’t want to learn two things at a time.
Screenshots of IDEs are pretty fast outdated anyways.
Use the IDE you are comfortable with because you only have to learn one new thing, Spring Boot.
Honestly, fighting with an IDE and learning a new tech at the same time is a waste of your time. Learn one after another and when you start with Spring Boot now, use an IDE you are familiar with.
What You Will Need
Java 8+
Maven (3.2+) or optionally Gradle (see note below)
IDE or Texteditor of your choice (the book is written IDE independent, but I use STS personally)
Installing and setting them up is not in the scope of this book.
You can use Gradle instead of Maven, but the book and the examples assume you are using Maven. However, I assume you are capable of converting it to Gradle yourself.
If you are new to Maven, check out the brief introduction to Maven in Appendix A. It will assist you in following along.
Understanding Spring Core
In the first chapter, we will take a closer look at the Spring Framework and what kind of problems it solves in the first place. We then examine how the core of it works and how to use it. We will focus on the basics here and ignore the numerous features it offers additionally; some of them will be covered further in the book.
If you already know what the Spring Core does and how it works, you can skip to the next chapter and directly start with Spring Boot.
We are using Maven as a build and dependency management tool in the book. If you are new to Maven, check out the brief introduction to Maven in Appendix A; it covers the basic to get started. And if you want to use Gradle, go ahead and use it, I assume you are capable of converting the dependencies to Gradle yourself.
What is the Spring Framework?
The Spring Framework provides an environment for developing Java applications so you can focus on developing your application logic. Standard functionality and inter-component connectivity are taken care of by Spring, and you save time in each project as you do not have to reinvent the wheels each time.
Spring uses the concept of Inversion of Control (IoC). IoC means that service calls are not hardwired but instead run through a framework, i.e., service A uses service B but does not know how B is instantiated - the IoC container does it.
This concept gives us some benefits like:
decoupling service calls from the actual implementation of the task
making it easier to change the implementation of a service
our application gets more modular, and we can switch