For the latest stable version, please use gotmpl4j Spring Boot 4.1.1.1!

gotmpl4j Spring Boot

Spring Boot integration for gotmpl4j — the pure-Java implementation of Go’s text/template engine. Two artifacts:

Artifact What it gives you

org.alexmond:gotmpl4j-spring-boot-starter

Auto-configuration: a ready-to-inject template engine, configuration properties, a compile cache, and optional MVC / WebFlux `ViewResolver`s so controllers can return view names.

org.alexmond:gotmpl4j-spring

Template functions that read from the running application — msg (i18n), env (config), bean, plus Spring Security (hasRole/isAuthenticated/…) and web (param/csrf/…) helpers. Ships with the starter.

1. Versioning — one branch per Spring Boot line

This project’s version tracks the Spring Boot release it builds against, in the form <boot-version>.<revision>:

Branch Spring Boot Example version

main

4.1.x

4.1.1.1

4.0

4.0.x

4.0.8.1

Pick the artifact version matching your application’s Spring Boot line. main always tracks the newest Spring Boot release; older lines get their own maintenance branch.

The engine itself (gotmpl4j-core, gotmpl4j-sprig) is Spring-free and versioned separately on plain semver in the gotmpl4j repository — one engine build serves every Boot line.

2. Quick start


    org.alexmond
    gotmpl4j-spring-boot-starter
    4.0.8.1
@Service
class GreetingService {

    private final GoTemplateService templates;

    GreetingService(GoTemplateService templates) {
        this.templates = templates;
    }

    String greet(String name) {
        return templates.render("greeting", Map.of("name", name));
    }
}

3. Template syntax and functions

Template syntax, the Sprig function library, and the extension SPI are documented with the engine: