An introduction to Spring Boot so you won't regret it
If you have this book in your hands, you may have plans to develop with Spring(Spring Boot) in the future.
Everyone feels anxiety and fear when trying something for the first time. (At the same time, you may feel excited). But that's a good thing. Because we strive to drown out the anxiety.
Whatever the reason, trying new things leads to growth. The more unknown it is, the greater the degree of growth. Therefore, for you who have taken that step, growth is waiting for you.
When I started learning about Spring, I bought a number of Spring-related books (because I was afraid). But I didn't have a satisfying book. With the intention of changing that situation, we published the first edition of this book in 2018. Since Spring is also evolving, I have published the second edition.
In this book, you will use Spring to create one web application. Start by learning from the basics of Spring and gradually complete your application. By doing this, you will be able to acquire not only Spring but also the knowledge necessary for web development.
In other words, you can level up from knowing nothing about web development to being able to master Spring at once.
However, this book emphasizes practice rather than theory. There are various learning methods, but actually experiencing it is one of the efficient ways to learn. This is because it is scientifically known that the output has a high retention rate of knowledge. Also, when you actually make it and execute it, your anxiety and fear will disappear, so you will gain confidence.
It is better to actually move your hands to make it, but at first it is okay to just read a book. Since all the sample code can be downloaded, you can create an application even from the middle.
In the second edition
I am very pleased to receive highly rated reviews since the first edition of this book was published.
[Review of the 1st edition]
In the second edition I have the following modifications.
- Added contents about MyBatis and JPA
- Modified REST to be more practical
- Supports SpringBoot 2.4
These are the functions that are often used in the development field. Therefore, more practical content is increasing.
Thoroughly pursue clarity!
In this book, it has been described as follows in order to facilitate understanding.
- Incorporate many illustrations
The ease of understanding changes greatly depending on whether or not there is a diagram at the time of explanation. For this reason, this book contains many illustrations to make it easier to understand.
- Step by step
There are some things to keep in mind when teaching something. That is to tell only one thing. Being told multiple things at the same time can be confusing. Besides, books can only explain with letters and figures. Therefore, I will tell you one by one.
- Clarify goals
Before actually making the sample code, I will explain what to make first. For example, ask them to create an application after explaining the contents with a screen image. Understanding is better if you know your goals.
We also put a lot of effort into explaining DI (Dependency Injection). Other books explain DI for advanced Java users and experienced Spring users. However, this book describes DI so that even Java beginners can understand it.
Structure of this book
Read this book in order, starting with Chapter 1, as you will gradually build your application. For example, first display the Hello World, then validation (input check), then screen layout, then database operation, and so on.
Target audience
In reading this book, it is desirable to have the following knowledge.
- Java basics
HTML basics
- SQL basics
Basic level knowledge is sufficient.
Application configuration
The Web application developed in this document will be created with the following configuration.
- Spring: 5
- Spring Boot: 2.4.1
- Database: H2
* This is the latest version at the time of writing.
Now, try this book.
* When browsing with e-books, I recommend browsing with a tablet device.
Table of Contents
1. Spring Overview
This chapter describes an overview of Spring.
1.1 What is Spring?
Spring is a framework for Java development. Previously there were several frameworks. However, it is common sense to use Spring for the framework of Java development. This is because it is easier and faster to develop than other frameworks. It's also feature-rich, so it's ready for any project.
1.1.1 What is a framework?
Let's first consider the case where we don't use a framework. In this case, build the application from scratch. For example, suppose you create a login function. In this case, it is necessary to create a program that retrieves user information from the DB and verifies the password.
Now consider a framework. The framework provides some common features in advance. Developers create only those parts of the function that they want to change. The framework then calls the program for that change. For the login function, the developer only creates SQL to retrieve user information. The framework provides other processing.
[Figure] What is the framework?
In other words, using the framework, you can create an application simply by creating the necessary part of the program. Since there is no need to create all the programs, the development efficiency will increase. So it is common sense to use frameworks in development.
Incidentally, the side from which the created program is called is called "Inversion of Control" (IoC for short). This idea can also be seen in DI (Dependency Injection)
1.2 What is Spring Boot?
Spring Boot is a framework that saves you the trouble of initializing Spring.
Before the advent of Spring Boot, Spring's initial configuration could cause it to trip. Because you had to prepare an xml file to use Spring's features. The need for expertise, such as how to write xml files, caused the initial setup to be cumbersome and delays in development.
To solve the problem, Spring Boot was created. In Spring Boot, you simply select the functions you want to use in your application. After that, Spring Boot will automatically perform the initial setup. You can easily change the setting by simply changing the value of the property. Spring Boot is now used because it can improve development efficiency.
And compare this with cake making is as follows.
- Spring
This is just the alignment of the cascading material.
- Spring Boot
If you choose the ingredients for making the cake, the cake will be made to some extent. All you have to do is put strawberries and make various decorations.
2. Building the Development Environment
Before creating a program, let's build a development environment.