Building your first Spring Boot Application

Hey folks, what’s up. In this tutorial, we are going to build our first ever spring boot application. Just spend your few minutes and you will have your first ever spring boot application.

But before beginning, let’s know something, why Spring Boot when we already have Spring Framework. With Spring Framework in Java, we do have lots of advantages like Dependency Injection, easy testable, reduction in plumbing code like JDBC, easy integration with other frameworks and so on. But it does have some demerits like need to manage lots of XML Configurations, monolithic to micro-services. So Spring Boot is introduced which retains the merits of Spring Framework and eliminates its demerits.

Now, lets start. Before beginning, you should know that Spring Boot application can be created with different ways like using Spring Initializer, Spring Boot CLI i.e. using Spring Tool Suite, or Customizing Spring Boot. For our learning purpose, we are going to use Spring Tool Suite (STS), which you can download from here.

After downloading STS, create new Spring Boot App like this:

Go to File -> New -> Spring Starter Project and then

Give your project name, add dependencies as per the requirement and just click the finish button. It will take some time to build your project, have patience.

Do you know that Spring Boot contains embedded Tomcat Server? Now you don’t have to download external severs and configure it just to run your application. Spring Boot does that for you. You just have to focus on your business logic not on the configuration. This is another great thing about Spring Boot.

In order to run your application, just right click on the project and click on Run As -> Spring Boot Application and you will get something like this:

First Spring Boot App

Voila, we’ve finally build our first spring boot application. You have already run your application on default port:8080, you can manage this port in and can set your desired port. However, we’ve not done anything to our web app. So lets display a simple message on it.

Create a class Display.class and paste the following code:

package com.example.demo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

public class Display {

	public String showMessage() {
		return "Hello folks!!";

@RestContoller and @RequestMapping are Spring framework annotations and we will discuss about such annotations in some other tutorial. For now let’s run our app again and run the url : localhost:8080/hello

In the further tutorial, we are going to build Real World Web Application performing CRUD operation using Angular and JPA. It will be fun 🙂