Spring Boot Tutorial

Hello guys, I am so glad to bring the Spring boot tutorial series. This tutorial is especially for beginners who want to understand and develop java application using Spring Boot. We will be using Spring Boot 2 for this series. So let’s start the Spring Boot 2 Tutorial.

The most common type of application we develop is web-based applications, that are backed by some relational database. But in recent times, microservices has become a hot cake. And its popularity is also valid because it enables an application to be more robust, flexible and scalable. As the software development process is evolving, the Spring Framework is also evolving to address this change.

Whether we want to build database-backed web-application or a modern application using microservices, we can do everything with the Spring Boot 2.0. In this series, we will be building our first modern web application using the Spring Framework.

What is the Spring Framework?

I know you must be excited to start writing a Spring application and I assure you before we end this series, we will have developed one. But first, it is very important for us to understand the basics of the Spring Framework. I have discussed the core concepts of the Spring here. I highly recommend you to go through it if you are new to the Spring.

Quick Summary

Any Java application is composed of many components (beans). Each component is responsible for its own functionality. Components (beans) coordinate with each other in an application to get the job done.

At the core of the Spring Framework, there is a container which is also called the Spring application context. The Spring Container is responsible to create, manage and wire beans within an application. The mechanism of wiring the beans is called Dependency Injection.

spring-container
Screenshot: Spring in Action

Along with the core container, Spring provides many other modules like a web framework, a variety of data persistence options, a security framework, monitoring features, microservices support, etc. necessary for any modern application.

There are different ways to configure and wire beans in Spring Application:

  1. Auto bean discovery and wiring (Check here)
  2. Explicit configuration using Java (Check here)
  3. Explicit configuration using XML

Spring Boot

Spring Boot came to rescue when developing an application using Spring Framework started getting complicated. Spring Framework comes with innumerable modules that we can add to our project to add functionalities. As modules keep on increasing, the application becomes huge and difficult to manage. Sometimes even version of different module starts conflicting and the application goes for a toss. Not just dependencies, it also becomes difficult to track configuration within application.

With the introduction of Spring Boot, auto bean discovery and wiring have gone to another level. Spring Boot has brought the concept of autoconfiguration where it can make reasonable guesses of what beans need to be configured and wired together, based on entries in classpath, environment variables and other factors. We will discuss this in more detail in future posts.

Why Spring Boot?

  1. As discussed above, Spring Boot provides a way to enable autoconfiguration. There is minimal manual configuration required in an application.

  2. Spring Boot favors annotation-based configuration over XML configurations. The annotation-based configuration is type-safe and less prone to errors.

  3. Spring Boot is based upon the concept of microservices. Modern applications are developed using architecture. Few of the benefits of a microservices architecture are:
    1. Rapid development
    2. Scalability is easy
    3. Minimal configurations

  4. Spring Boot comes with embedded application servers. That means we do not have to worry about deployment. Our application can be deployed as a standalone JAR.

  5. Spring Boot provides ready to use templates for your application which are called Spring Boot Starters. With Spring Boot starter packages, we do not have to worry about dependency management.
    We can simply use the starter package provided by Spring Boot and all the dependencies related to it will be handled by Spring automatically. Some of the started packages are:
NameDescription
spring-boot-starter-thymeleafIt is used to create an MVC application using Thymeleaf template.
spring-boot-starter-actuatorIt is used to monitor and manage your Java application.
spring-boot-starter-securityIt is used to enable spring-security in your application.
spring-boot-starter-webIt is used to create REST endpoints in an application.
spring-boot-starter-testIt is used to test the Spring Boot Application. It downloads necessary dependencies like Junit, Mockito, etc.
spring-boot-starter-mailIt is used to enable mail feature in a Java application.
spring-boot-starter-data-mongodbIt is used to integrate MongoDB into an application.

Above, we have listed some of the most commonly used Spring Boot starter packages which we can use directly to start building our application rapidly. These starter packs offer these benefits:

  • Your build file will be smaller since you don’t have to declare a dependency on every library you need.

  • You think of libraries as a capability they provide rather than each library’s name.

  • You don’t have to worry about the library version. You only have to specify the Spring Boot version.

I hope I am able to make you understand why choosing Spring Boot for a Java Application development is important and what all features Spring Boot brings to the table by now. Don’t worry if this post has become too theoretical for you. We will quickly dive into how to build an application using Spring Boot in our next post.