Easy learning with example program codes

Spring Boot Thymeleaf Hello World

Spring boot is a module of spring framework which is used to create stand-alone, production-grade Spring based Applications with minimum programmer’s efforts. It is developed on top of core spring framework. The main concept behind spring boot is to avoid lot of boilerplate code and configuration to improve development, unit test etc.

Spring Boot Thymeleaf Hello World

Directory Structure

Spring security

pom.xml file

Modify auto created POM file. We need to add parent in pom to make it a spring boot application. After that add spring-boot-starter-thymeleaf dependency and java version.

<project xmlns="" xmlns:xsi=""
	<!-- hot swapping, disable cache for template, enable live reload -->
			<!-- Package as an executable jar or war -->

Now, right click on project -> click on Maven -> click on update project -> Popup window will open -> click Ok to update the project.
It is a initializer class which runs a SpringApplication.

package com.codesjava;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
public class App extends SpringBootServletInitializer {
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(App.class);
    public static void main( String[] args ) {, args);  

package codesjava;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
public class HelloWorldController {
	private String message = "Hello World";
	public String welcome(Map<String, Object> model) {
		model.put("message", this.message);
		return "helloWorld";


<!DOCTYPE html>
<html xmlns:th="">
<title>Insert title here</title>
<h2>Spring Boot Web Thymeleaf Example</h2>
	<span th:text="'Message: ' + ${message}"></span>

Hit http://localhost:8080/ in the browser, following output will come.
Spring security

Please follow and like us:

Spring Tutorial

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki