Spring Boot

The jtwig-spring-boot-starter project allows one to easily integrate Jtwig with Spring Boot. Just by adding the dependency to your project, spring-boot will then load JtwigViewResolver.

Default Configuration

If you include jtwig-spring-boot-starter in your project, by default it will set the view resolver with prefix classpath:/templates/, suffix will be set as .twig and the Jtwig default configuration will be used. Note that, jtwig-spring-boot-starter uses jtwig-web which extends the default Jtwig Core configuration, as already mentioned.

Costumize Configuration

It is still possible to customize JtwigViewResolver to define prefix, suffix and also Jtwig Environment. For that JtwigViewResolverConfigurer interface can be extended by @Configuration annotated class. Note that, such class needs to be injected by spring-boot to the application context.

public class JtwigConfig implements JtwigViewResolverConfigurer {
    public void configure(JtwigViewResolver viewResolver) {
        viewResolver.setRenderer(new JtwigRenderer(EnvironmentConfigurationBuilder
                .extensions().add(new MyExtension()).and()

    private static class MyExtension implements Extension {
        public void configure(EnvironmentConfigurationBuilder configurationBuilder) {
            // change config

The previous example sets the JtwigViewResolver renderer with an extended version of the EnvironmentConfiguration including a dummy Extension. This working example can be found in jtwig-examples.


Integration of Jtwig Spring Boot in your project will depend on the dependency management mechanism being used. Also, you will need to make sure jcenter is part of your repository list. The most recent version is 5.85.3.RELEASE.


repositories {

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