Spring Boot Framework

What is Spring Boot ?
What is Spring ?

Introduction

Spring Boot
Maven

Creating a Project

Step-1: Create a simple Maven Project

Step-2: Convert to Spring Project using Spring Boot Convention

Put the below dependency in pom.xml.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.6.RELEASE</version>
</parent>
Step-3: Converting it to a Web Application

Add the web dependencies to make it a web application.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.2.6.RELEASE</version>
</dependency>
Step-4: Use the appropriate Java version
<properties>
    <java.version>1.8</java.version>
</properties>

Starting the Spring Boot App

Create a class App.java with below code.

package com.kodefork.articles;

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

@SpringBootApplication
public class App {
    public static void main(String[] args){
        // Create a servlet container and run
        SpringApplication.run(App.class, args);
    }
}

Notes:

  • SpringApplication has a static method run() that does all the magic, it takes class App and starts spring boot application as it it annotated by **@SpringBootApplication **.
Starting Spring Boot

Adding a Controller

Controller
Spring MVC Framework
Writing a REST Controller

Let’s perform a quick side-by-side comparison, so we can have a bird’s eye view of the constraints’ functionality and easily spot their differences: