Table of contents
1.
Introduction
2.
Requirements
3.
Setting up the project
4.
Frequently Asked Questions
5.
Key Takeaways
Last Updated: Mar 27, 2024

Spring Boot Hello World Example

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Spring Boot is a project that uses the Spring Framework as its foundation. It makes setting up, configuring, and running simple web-based applications easier and faster. 

In this article, we will learn Spring Boot. You must have a basic understanding of Spring Framework before learning Spring Boot.

In this blog, we will be creating a Maven project for the Hello world example.

Requirements

Before starting with the project we need to following tools and software to create our project

  • Spring Boot 2.6.2
  • JavaSE 1.8
  • Maven 3.3.9
  • Any IDE or editor of your choice

Setting up the project

We will create a Maven project so to make the project follow the following steps

We will create a Maven project so to make the project follow the following steps

  1. Open Spring initializr  https://start.spring.io/
  2. Provide the Group name and  Artifact id.
  3. Fill up the name and Description of the project.
  4. Select the jar packaging and desired java version
  5. Select the Maven Project and language Java
  6. Select the version of spring boot.
  7. Add Spring web as a dependency.
  8. Click on generate button it will wrap all the specifications provided by you into a jar file and will download a .rar file
  9. Extract the RAR File and import the project to your IDE. When the project is imported the IDE show the following directory structure.
  10. Create a package with the name com.demo.controller inside folder src/main/java.

Create a controller class with the name HelloWorld

11. Create a method hello() that returns “Hello world” String.

package com.demo.controller;  
import org.springframework.web.bind.annotation.RequestMapping;  
import org.springframework.web.bind.annotation.RestController;  
@RestController  
public class HelloWorld   
{  
@RequestMapping("/")  
public String hello()   
{  
return "Hello World";  
}  
}  

 

12. Create and run the HelloWorldApplication.java

package com.demo;  
import org.springframework.boot.SpringApplication;  
import org.springframework.boot.autoconfigure.SpringBootApplication;  
@SpringBootApplication  
public class HelloWorldApplication  
{  
public static void main(String[] args)   
{  
SpringApplication.run(HelloWorldApplication.class, args);  
}  
}  
You can also try this code with Online Java Compiler
Run Code


Output:

Must Read Spring Tool Suite.

Frequently Asked Questions

1) What is Spring?

The Spring framework is one of the most popular application development frameworks of Java. The important feature of the spring framework is dependency injection or the Inversion of Control.

2) What is a Spring Boot?

Spring Boot is a Spring module that extends the Spring framework's RAD (Rapid Application Development) capabilities.

It's used to create stand-alone spring-based applications that we can just run because spring configuration is minimal.

3) What is the latest version of spring boot?

The current latest stable version of spring boot is 2.6.2

Key Takeaways

In this blog, we discussed setting up a hello world example in spring boot. We discussed the requirements and steps in detail to develop the hello world project in spring boot.

Apart from this, you can also expand your knowledge by referring to these articles on Spring Boot dependency management and Spring Boot packaging.

You can also consider our Spring Boot Course to give your career an edge over others.

Happy Learning!

Live masterclass