Spring boot provide view technology to front development. here is spring boot freemarker example. spring-boot-starter-freemarker dependency requires in class path so spring boot automatically configure freemarker configuration.   For freemarker require .ftl template file which must be available inside resources\templates folder.


spring boot freemarker example

spring boot freemarker example


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <description>spring boot freemarker example</description>
    <!-- Inherit defaults from Spring Boot -->
        <!-- Provided -->
            <groupId>org.springframework.boot</groupId>                <!-- for tomcat web container-->
        <dependency>                 <!--  its requires for spring boot freemarker  -->


Its like normal spring controller which handle require and return String which is name of freemarker template name which is available in side resources\templates. Spring will try to find resources\templates\[TEMPLATE_NAME].ftl file.

package com.javadeveloperzone.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
 * Created by JavaDeveloperZone on 19-07-2017.
public class FreeMarkerController {
    @GetMapping("/welcome")                     // it will handle all request for /welcome
    public String welcome(ModelMap madelMap) {
        java.util.List<Employee> employeeList=new java.util.ArrayList<>();
        employeeList.add(new Employee(1,"Jone"));
        employeeList.add(new Employee(2,"Moke"));
        employeeList.add(new Employee(3,"Rijos"));
        return "welcome";           // welcome is view name. It will call welcome.jsp


package com.javadeveloperzone;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
 * Created by JavaDeveloperZone on 19-07-2017.
// Using a root package also allows the @ComponentScan annotation to be used without needing to specify a basePackage attribute
public class SpringBootConfig extends SpringBootServletInitializer {
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringBootConfig.class);
    public static void main(String[] args) throws Exception {
        SpringApplication.run(SpringBootConfig.class, args);            // it wil start application


package com.javadeveloperzone.controller;
 * Created by JavaDeveloperZone on 26-09-2017.
public class Employee {
    Employee(int id, String name) {
        this.id = id;
        this.name = name;
    private int id;
    private String name;
    public String getName() {
        return name;
    public void setName(String name) {
        this.name = name;
    public int getId() {
        return id;
    public void setId(int id) {
        this.id = id;


It must be available insider resources\templates folder.

    <title>spring boot freemarker example</title>
<h1>Here is list of employee using spring boot freemarker</h1>
<#list users as user>


spring boot freemarker example demo

spring boot freemarker example demo


freemarker document

Spring boot freemarker document

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *