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
-
Open Spring initializr https://start.spring.io/
- Provide the Group name and Artifact id.
- Fill up the name and Description of the project.
- Select the jar packaging and desired java version
- Select the Maven Project and language Java
- Select the version of spring boot.
- Add Spring web as a dependency.
-
Click on generate button it will wrap all the specifications provided by you into a jar file and will download a .rar file
-
Extract the RAR File and import the project to your IDE. When the project is imported the IDE show the following directory structure.
- 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!