Jtwig 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.


Check the most recent version, go to bintray.


repositories {
dependencies {
    compile 'org.jtwig:jtwig-spring-boot-starter:5.X'




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) {

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.