DEV Community

Rey Tech Inc.

Spring Boot Hello World Example by using STS

zarlihninn profile image Zar Li Hnin Updated on ・4 min read

What is Spring Tool Suite (STS)?

  • STS is an IDE and eclipse-based development environment that is used to develop Spring applications.
  • It is easy to run, implement, deploy, and debug the application.
  • It provides a ready-to-use environment to implement, run, deploy, and debug the application. It validates our application and provides quick fixes for the applications.


You can use either IntelliJ, Eclipse, or STS.

Source Code

You can refer to the source code below.

How to install Spring Tool Suite (STS)

It can be either installed by downloading STS from or can be installed as a plugin to an existing installation of Eclipse JEE.

In this tutorial, let’s install STS as a plugin in Eclipse.

  1. Help → Eclipse Marketplace

  2. Type Spring Tool Suite in the search box, and click the Go button.
    Alt Text
    Alt Text
    After installation, restart Eclipse.

How to create a project

File → New → Spring Starter Project
Alt Text
Fill necessary information
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.

  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 Java version you want to use.

  6. 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.
    Select Dependencies
    Alt Text
    Choose Spring Web, Spring Boot DevTools, and Thymeleaf by searching.

    • 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.

And now, you can see the project in Project Explorer.
Alt Text

Let’s see the files from the project folder

  • 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 filled and selected when creating a project, 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() {


Let’s add some coding files to show Hello World

Let’s add and 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>

Let’s run

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