Spring Boot Introduction Tutorial

By | July 31, 2020

Spring Boot is a framework used to develop the Java-based Application. It is completely an Open Source. It provides so many inbuilt features that save the time spent on configuration. With the help Spring boot, you can easily develop a production-ready application.

Overview of things you will learn in this tutorial

  1. Advantage of Spring Boot
  2. Objective of Spring Boot Implementation.
  3. Why should go for Spring Boot?
  4. How does Spring Boot Work with Real-Time Example?

Who can read this tutorial?

This tutorial is dedicated to anyone who loves to code in java and wanted to build the application without investing their more time on configuration. This tutorial covers all the important features which required build simple to advanced level application.

What are the things you should know before starting this tutorial?

You must have basic knowledge of Java and if you have a little bit of knowledge of maven then it will be helpful for you. If you are completely new to the Java World then I recommend you please check out the tutorial to learn the basics of Java.

Introduction to Spring Boot

With Spring boot you develop the stand-alone application, it also comes up with an embedded Tomcat server, so that can easily run your code. There is no need to additionally add the server to run.

Spring boot comes in the market with the main goal is reduce the effort put by the developer on setting up the configuration or you can say time required to set up the whole thing for the project before starting on the actual coding part.

Advantage of Spring Boot

  1. Developers are productive.
  2. Reduces the overall development duration of Application.
  3. Very simple and easy to work with Spring Boot.

Objective of Spring Boot Implementation

  1. To reduce the XML configuration part.
  2. More focus on business logic code instead of XML configuration.
  3. Make the application to run independently.

Why should go for Spring Boot?

  1. It is mostly based on annotation for configuration or creating Java Objects or beans.
  2. You can achieve the proper data transactions between database and application.
  3. In spring boot, no need to do the configuration manually, it provides Auto Configuration feature.

How does Spring Boot Works?

Using the annotation @EnableAutoConfiguration on the base class, it will automatically configure the project based on the jar files or dependencies you have provided. For example, you have added the dependency for Postgresql or MySQL database on the classpath of the project, but you have not done any configuration for database connectivity, then Spring Boot will automatically configure the in-memory database such as H2 Database.

As you all know the driving class in java is the one which contains a static main() method. In Spring boot also along with main() we have @SpringBootApplication annotation. The class which tagged with annotation @SpringBootApplication and having main() are called Driving Class or Entry class.

package com.pixelTrice.firstSpringBootApplication;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class FirstSpringBootApplication {

	public static void main(String[] args) {
		SpringApplication.run(FirstSpringBootApplication.class, args);
	}

}

With the help of @ComponentScan annotation, spring boot scans and automatically creates Objects or beans of components in the application context when the application starts running.

Note: Component is nothing but a class that is present in the same package(folder) or child package of the package where the driving class or entry class is present.

@ComponentScan
public class FirstSpringBootApplication {

	public static void main(String[] args) {
		SpringApplication.run(FirstSpringBootApplication.class, args);
	}

}

Java Beans or beans is an object of component class in Spring Boot.

@SpringBootApplication annotation is the combination of three different annotations such as @Configuration, @EnableAutoConfiguration, @ComponentScan.

@SpringBootApplication = @Configuration + @EnableAutoConfiguration + @ComponentScan.

@Configuration: For the Class which tagged with @Configuration annotation, it indicates to the Spring to create the bean or object for this class in application context or in spring container.

Note: If you are using @SpringBootApplication annotation then no need to use @CompoentScan or any other two. Because as I told you @SpringBootApplication is the combination of @Configuration, @EnableAutoConfiguration, @ComponentScan.

Summary

In this article, you have learned the basics of the Spring Boot. This is just a Spring Boot Introduction Tutorial. In the next article, I will explain to you how to quick start with Spring Boot Application.

Thank You So much for reading my article. If want to learn some topic related to basic java, please do check out my other articles from here. I explained everything in detail along with Real World examples and application-based examples.

Leave a Reply

Your email address will not be published. Required fields are marked *