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.
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.
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:
- Auto bean discovery and wiring (Check here)
- Explicit configuration using Java (Check here)
- Explicit configuration using XML
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?
- As discussed above, Spring Boot provides a way to enable autoconfiguration. There is minimal manual configuration required in an application.
- Spring Boot favors annotation-based configuration over XML configurations. The annotation-based configuration is type-safe and less prone to errors.
- Spring Boot is based upon the concept of microservices. Modern applications are developed using architecture. Few of the benefits of a microservices architecture are:
- Rapid development
- Scalability is easy
- Minimal configurations
- 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.
- 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:
|spring-boot-starter-thymeleaf||It is used to create an MVC application using Thymeleaf template.|
|spring-boot-starter-actuator||It is used to monitor and manage your Java application.|
|spring-boot-starter-security||It is used to enable spring-security in your application.|
|spring-boot-starter-web||It is used to create REST endpoints in an application.|
|spring-boot-starter-test||It is used to test the Spring Boot Application. It downloads necessary dependencies like Junit, Mockito, etc.|
|spring-boot-starter-mail||It is used to enable mail feature in a Java application.|
|spring-boot-starter-data-mongodb||It 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.