DEV Community

Rey Tech Inc.

Spring Boot Hello World Example by using Spring Initilizr

zarlihninn profile image Zar Li Hnin ・5 min read


In this article, you'll be able to start up your Spring Boot application and show Hello World and a message on your browser.

There are four ways to create Spring Boot project which are:

  1. Spring Initializr
  2. Spring Tool Suite (Spring Boot Starter Plugin)
  3. Simple Maven Project
  4. CLI (Command Line Interface)

If you want to create a project easily and quickly, the best ways are using 1. Spring Initializr or 2. Spring Tool Suite. In this tutorial, we will show you how to create Spring Boot project using Spring Initializr.

What is Spring Initializr?

The Spring Initializr is a web-based tool provided by the Pivotal Web Service. You can easily generate the structure with the help of Spring Initializr and you can add any dependencies and necessary configuration. After that, you can get a basic project structure and either a Maven or a Gradle build specification to build your code with.


You can use either IntelliJ, Eclipse, or STS.

Source Code

You can refer to the source code below.

Let’s start to show Hello World with Spring Initializr

Step 1

You can create a simple Spring Boot project by visiting the following site.
Alt Text

  • Choose your build tool: Maven or Gradle.
  • Choose Java Language to create Java web-based applications.
  • Choose Spring Boot version (2.3.1 version in this case)

Step 2

Alt Text

  1. Configure Group for your component which is the root package name to use.
  2. Configure Artifact for your component which is the name of the project. When configuring Artifact, you will be noticed the project name is automatically filled. Alt Text
  3. Fill description for your project.
  4. Fill the root package of the project. If not specified, the value of the Group attribute is used.
  5. Choose Jar or War.
    • If you want to execute Java application containing Java class files, and associated metadata, you can choose Jar.
    • If you want to develop Web application containing Servlet, JSP, HTML, JavaScript, and other necessary files, you can choose War.
  6. Choose Java Version you want to use.

Step 3

Spring Initializr offers a fast way to pull in all the dependencies you need for an application and does a lot of the setup for you.
Alt Text
Choose Spring Web, Spring Boot DevTools, and Thymeleaf by clicking Add Dependencies.

  • The spring-web dependency contains common web-specific utilities for both Servlet and Portlet environments, while spring-web MVC enables the MVC support for Servlet environments.
  • The Spring-boot-devtools automatically reload your project when you change some code in your classpath file.
  • Thymeleaf is a Java-based library or template engine to create web-based applications.

Step 4

Alt Text
You can get the following project zip file by clicking the GENERATE button.
Alt Text

Step 5

Now, you can import your project zip file in your IDE (e.g. Eclipse, Intellij). In this tutorial, we will use Eclipse IDE and you need to follow these steps to import your project file.

  1. Click File->Import. Alt Text
  2. Search and select Existing Maven Projects and after clicking Next, browse the project zip file. Alt Text Now, we have imported project completely and you can see the project in project explorer. Alt Text

  • It is the main class of Spring Boot Project.
package com.reytech.demo;

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

public class DemoApplication {

    public static void main(String[] args) {, args);



  • As we defined in Spring Boot Initializr GUI, you can see the following properties, description, dependencies, etc.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
        <relativePath/> <!-- lookup parent from repository -->
    <description>Demo project for Spring Boot</description>






  • It contains the basic context that can be used to start writing the tests as we start developing the application.
package com.reytech.demo;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

class DemoApplicationTests {

    void contextLoads() {


Step 6

Let’s add, hello.html and message.html to show Hello World and some message on your browser.

  • Under the demo package, please create a controller package and HomeController.
  • Under src/main/resources/templates directory, create hello.html and message.html. Alt Text

  • hello() function calls hello.html when URL is localhost:8080/
  • message() function calls message.html and you can set the custom message on the controller by using model.addAttribute("message", "This is a custom message");
package com.reytech.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

public class HomeController {

    public String hello(){
        return "hello";
    public String message(Model model) {
        model.addAttribute("message", "This is a custom message");
        return "message";


<!DOCTYPE html>
<html xmlns=""
    <meta charset="UTF-8">
    <title>Spring Demo Project</title>
    <h1>Hello World</h1>


  • The th:text=”${attributename}” tag attribute is used to display the value of model attributes.
<!DOCTYPE html>
<html xmlns=""
    <meta charset="UTF-8">
    <title>Spring Demo Project</title>
    <h1 th:text="${message}"></h1>

Step 7
Just run the server and navigate to http://localhost:8080/
Alt Text
And navigate to http://localhost:8080/message.
You can see the following message on your browser.
Alt Text

Thank You.


Discussion (0)

Forem Open with the Forem app