Spring Reactive, Thymeleaf Hello World (Spring Webflux + Thymeleaf + JS/CSS)

  • 4.1/5
  • 5063
  • 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:

Dependencies

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:

Static Resources
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

Thymeleaf UI

Source Code

Index
How to Implement PostgreSQL Full-Text Search with Spring Boot

15 min

Spring's transaction management with the @Transactional annotation

9 min

Spring Boot Rest APIs with PostgreSQL (Spring Boot + Rest APIs)

15 min

Caching in Spring Boot (@Cacheable, @CacheEvict & @CachePut)

21 min

Declarative REST Client in Spring Boot (Spring 6 HTTP Interface)

13 min

Circuit Breaker in Spring Boot (Spring Cloud Circuit Breaker + Resilience4j)

11 min

Profiling a Spring Boot application with Pyroscope

7 min

Dockerize Spring Boot app and Push image to DockerHub (Spring Boot + DockerHub)

4 min

Service discovery in Spring Boot (Spring Cloud + Netflix Eureka)

9 min

Creating a Jenkins Pipeline for Spring Boot application

2 min

Edge Server Pattern in Microservices (Spring Cloud Gateway)

7 min

Circuit Breaker Pattern in Microservices (Spring BOOT + Resilience4j)

4 min

Monitoring Microservices (Spring Boot + Micrometer + Prometheus + Grafana)

7 min

Spring Cloud config server setup with Git

8 min

Distributed Tracing in Microservices (Spring Cloud Sleuth + Zipkin)

9 min

Circuit Breaker Pattern with Resilience4J in a Spring Boot Application

24 min

Deploying Spring Boot microservices on Kubernetes Cluster

12 min

Reactive programming in Java with Project Reactor

50 min

Spring Reactive with PostgreSQL (Spring Boot WebFlux + PostgreSQL)

13 min

Spring Reactive, Thymeleaf Hello World (Spring Webflux + Thymeleaf + JS/CSS)

9 min

Problem JSON (application/problem+json) in Spring WebFlux

15 min

Spring Boot Login/Logout (Spring Security + MySql + Thymeleaf)

21 min

Securing Server-to-Server Communication with "Spring Boot" & "OAuth 2"

18 min

Sending Emails in Spring Boot via SMTP

7 min

How to create a basic Spring 6 project using Maven

5 min

Spring Boot, Thymeleaf Hello World (Spring Boot + Thymeleaf + JS/CSS)

9 min