logo © 2014

Spring Boot Quick Start

This quick start explains how to integrate Jtwig with Spring Boot.

1. Dependencies

Depending on the dependency management mechanism used, adding Jtwig dependencies may differ.

To integrate Jtwig with Spring Boot add the org.jtwig:jtwig-spring-boot-starter:5.85.3.RELEASE dependency. Another important aspect is to add the jcenter repository as Jtwig bundles are stored in bintray.


repositories {

dependencies {
    compile "org.jtwig:jtwig-spring-boot-starter:5.85.3.RELEASE"






If you don't make use of dependency management systems, it is also possible to download the dependencies via bintray.

2. Jtwig Template

An example of a Jtwig template placed in the classpath, with path index.twig. Note that, Jtwig Spring Boot integration sets the default template location as /templates in the classpath, with files suffixed with .twig.

Hello {{ name }}!

3. Controller Code

An example of a simple Servlet implementation can be seen below.

package org.jtwig.boot.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

public class SampleController {
    public String indexAction (ModelMap model, @PathVariable("name") String name) {
        model.addAttribute("name", name);
        return "index";

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);

All the listed code can be found in Jtwig Examples - Gradle Spring Boot Simple.