Featured Article

Spring Boot FreeMarker Tutorial: A Comprehensive Step-by-Step Guide

Kenneth Jul 13, 2026

Spring Boot, the popular Java-based framework for building microservices and production-ready applications, offers excellent support for various templating engines. Freemarker, a comprehensive template engine, is one of them. This tutorial guides you through integrating Freemarker with Spring Boot to leverage its powerful features and create dynamic web pages.

Coloring Tutorial how to draw for alcohol Coloring or Digital Coloring
Coloring Tutorial how to draw for alcohol Coloring or Digital Coloring

Before diving in, make sure you have Java Development Kit (JDK) 1.8 or later, Apache Maven, and a favorite code editor or IDE installed. This tutorial assumes you're using Spring Boot 2.5.0 and Freemarker 2.3.30.

Art Project for Kids: EASY How to Draw & Watercolor Paint a Garden Boot with Flowers & Butterflies!
Art Project for Kids: EASY How to Draw & Watercolor Paint a Garden Boot with Flowers & Butterflies!

Setting Up the Project

First, let's configure Freemarker in a Spring Boot project. If you're using Spring Initializr, add 'Freemarker' under 'Dependencies'. For an existing project, add the following dependency to your pom.xml:

how to draw leather boot | alcohol markers
how to draw leather boot | alcohol markers

```xml org.springframework.boot spring-boot-starter-freemarker 2.5.0 ```

Next, configure Freemarker settings in application.properties:

```properties spring.freemarker.cache=false spring.freemarker.suffix=.ftl spring.freemarker.content-type=text/html spring.freemarker.template-loader-path=classpath:/templates/ ```

Creating a Simple template

How to draw boots step by step easily
How to draw boots step by step easily

Create a new file named hello.ftl in src/main/resources/templates/ directory. Add the following content:

```html Hello World

Hello, World!

Have a nice day!

Free Templates - Crafts on Sea
Free Templates - Crafts on Sea

```

Accessing the Template

Create a new Spring MVC controller to access the template:

```java import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller public class MainController { @GetMapping("/") public String viewHomePage() { return "hello"; } } ```

Now, accessing http://localhost:8080/ should display the "Hello, World!" message on your browser.

how to draw a boot step by step instructions for kids and beginners in this video, you can learn how to draw boots
how to draw a boot step by step instructions for kids and beginners in this video, you can learn how to draw boots

Dynamic Content

Let's make the template dynamic by adding some content from the Spring Boot application.

How to Draw a Cowboy Boot
How to Draw a Cowboy Boot
Muddy Boots - An Easy Spring Craft for Toddlers!
Muddy Boots - An Easy Spring Craft for Toddlers!
a painting of pink rain boots with flowers in the bottom and daisies around them
a painting of pink rain boots with flowers in the bottom and daisies around them
Spring Renewal: The Joy of Fresh Sprouts and Rubber Boots
Spring Renewal: The Joy of Fresh Sprouts and Rubber Boots
How To Draw A Rain Boot With Spring Flowers
How To Draw A Rain Boot With Spring Flowers
an open book with instructions on how to paint flowers and plants in different stages of blooming
an open book with instructions on how to paint flowers and plants in different stages of blooming
Cowboy Boot Print Out, Preppy Cowgirl Boots Drawing, Cowgirl Boots Emoji, Cowboy Boots Collage, Cowgirl Boot Illustration, Cowboy Boot Illustration, Animated Cowgirl Boots, Cowgirl Boots Illustration, Cowboy Boots Illustration
Cowboy Boot Print Out, Preppy Cowgirl Boots Drawing, Cowgirl Boots Emoji, Cowboy Boots Collage, Cowgirl Boot Illustration, Cowboy Boot Illustration, Animated Cowgirl Boots, Cowgirl Boots Illustration, Cowboy Boots Illustration
the instructions for how to draw a waterfall
the instructions for how to draw a waterfall
a pair of boots with flowers on them
a pair of boots with flowers on them

Create a new model class for data:

```java public class Greeting { private String name; private String message; public Greeting(String name, String message) { this.name = name; this.message = message; } } ```

Passing Data to the Template

Update the controller to pass data to the template:

```java import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @Controller public class MainController { @GetMapping("/") public String viewHomePage(Model model) { Greeting greeting = new Greeting("World", "Have a nice day!"); model.addAttribute("greeting", greeting); return "hello"; } } ```

Update the Freemarker template hello.ftl to access the data:

```html Hello ${greeting.name}!

Hello, ${greeting.name}!

${greeting.message}

```

Accessing http://localhost:8080/ now displays "Hello, World!" followed by "Have a nice day!" thanks to the dynamic content.

Else Clause andstill/otherwise Directives

Freemarker provides directives like else, still, and otherwise to create conditional logic. Here's an example using still:

```html

${greeting.message still 'Something went wrong!'}

```

If greeting.message is null, it will display "Something went wrong!"

With these steps, you've successfully integrated Freemarker into your Spring Boot project, created dynamic content, and explored some Freemarker directives. Dive deeper into Freemarker documentation to unlock its full potential in your Spring Boot applications. Happy coding!