Built and Run the example

In this example, we are using the web-based Spring Initializr interface to generate the package. Here we have added web dependency only to demonstrate the running, building jar/war and understanding build.gradle / pom.xml

Step 1: Open https://start.spring.io to initialize your project with your selected dependencies. Here we are using 'Spring Web', 'Thymeleaf', and 'Spring Boot DevTools' dependencies for the hello world demonstration. 


Now, click on the generate button, it will start downloading a demo.zip file.

Step 2: Extract the downloaded zip in step 1. Import this project to your favorite IDE by navigating the extracted folder path and selecting the pom.xml or build.gradle file, you will get pom.xml when your project is a Maven project and build.gradle if your project is a Gradle project. Here we will be using IntelliJ Idea. 





Click on OK and follow the instructions with default settings.

On successful importing, you will get the main runner class DemoApplication.java 

	package com.example.demo;

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

	public class DemoApplication {

		public static void main(String[] args) {
			SpringApplication.run(DemoApplication.class, args);



If you selected Maven project then you will get pom.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
		<relativePath/> <!-- lookup parent from repository -->
	<description>Demo project for Spring Boot</description>







And if you have selected Gradle project then you will get build.gradle file.

plugins {
	id 'org.springframework.boot' version '2.2.6.RELEASE'
	id 'io.spring.dependency-management' version '1.0.9.RELEASE'
	id 'java'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
	runtimeClasspath {
		extendsFrom developmentOnly

repositories {

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	developmentOnly 'org.springframework.boot:spring-boot-devtools'

	testImplementation('org.springframework.boot:spring-boot-starter-test') {
		exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'

test {


Step 3: Now its time to write your application logic. Add a HelloController.java in package com.example.demo.


package com.example.demo;

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

public class HelloController {

    public String helloPage(Model model){
        String s = "Hello World Example";
        return "hello";

 Note: Here we have used

          @Controller to make the HelloController Class to behave as a request controller.

          @RequestMapping to name the request URL and hello page is returning String "hello" means Thymeleaf template engine will search for hello.html


Step 4: Add hello.html in resources/templates/  folder.

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <title>Spring Boot Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<div class="container">
    <div class="jumbotron">
        <h1>Spring Boot Tutorials</h1>
        <p th:text="${var1}"></p>
    <p><strong>Easytutorials.live</strong> provides simple and comprehensive tutorials on spring-boot, thymeleaf and linux.</p>
    <p>visit  <a href="http://easytutorials.live">easytutorials.live</a> .</p>


 Note: Here we have used html template from w3school bootstrap 4 example.

<p th:text="${var1}"></p> is used to write the object's value inside paragraph tag defined in the helloPage method of HelloController.java 


Step 5: Now its turn to run this example by clicking on Run button from IDE or you can run from Termial/cmd, go to the projects directory.

  If you are Linux user and using terminal then run the following command:

     $ ./mvnw spring-boot:run for Maven project

     $ ./gradlew bootRun for Gradle project

  If you are a Windows user and using cmd then run the following command:

     $ mvnw.cmd spring-boot:run for Maven project

     $ gradlew.bat bootRun for Gradle project