Spring Reactive, Thymeleaf Hello World (Spring Webflux + Thymeleaf + JS/CSS)
- 4.1/5
- 6029
- Jul 20, 2024
In this article we will see how to create a "Spring Reactive (Webflux) project with "Thymeleaf", we will also see how to import "css", "js" and "images" and populate dynamic data.
1) Dependencies
Let's create a project with , make sure to add required dependencies as shown in the picture below:
The final "pom.xml" should look something like this:
2) Static Resources
We should add static resources like: "js", "css" and "images" in "src/main/resources/static" folder and "Thymeleaf(.html)" files in "src/main/resources/templates" folder as shown in the image below:
app.css
index.html
3) Controller
This is the place to define "requestMappings", please note how "Rendering" is used to send data from "Controller" to "Thymeleaf's" .html file.
4) Service
This is just an abstraction between the data layer and the controller. We are generating some fake data here to show it on the UI, but in a real scenario all the data comes from a datasource.
5) Model
This is a simple model; we used it to send "employee" data from controller layer to view layer (thymeleaf).
6) Spring Boot
This is plain old Spring Boot driver class; all the execution starts from here.
7) Testing
Now we are all done with our project setup; lets run the application and navigate to home page : http://localhost:8080