Spring Boot Thymeleaf Hello World
Directory Structure
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.
4.0.0 codesjava SpringBoot04 0.0.1-SNAPSHOT jar SpringBoot04 http://maven.apache.org 1.8 org.springframework.boot spring-boot-starter-parent 1.4.2.RELEASE org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-devtools true junit junit 3.8.1 test org.springframework.boot spring-boot-maven-plugin
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.
App.java
package com.w3schools360; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.support.SpringBootServletInitializer; @SpringBootApplication public class App extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(App.class); } public static void main( String[] args ) { SpringApplication.run(App.class, args); } }
HelloWorldController.java
package w3spoint; import java.util.Map; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class HelloWorldController { private String message = "Hello World"; @RequestMapping("/") public String welcome(Map<String, Object> model) { model.put("message", this.message); return "helloWorld"; } }
helloWorld.jsp
Insert title here Spring Boot Web Thymeleaf Example
Hit http://localhost:8080/ in the browser, following output will come.