Skip to content

Spring Boot Starter

This starter is compatible with Spring Boot 3.x!

Add required dependencies

<dependency>
    <groupId>gg.jte</groupId>
    <artifactId>jte-spring-boot-starter-3</artifactId>
    <version>3.2.5</version>
</dependency>
<dependency>
    <groupId>gg.jte</groupId>
    <artifactId>jte</artifactId>
    <version>3.2.5</version>
</dependency>
implementation "gg.jte:jte-spring-boot-starter-3:3.2.5"
implementation "gg.jte:jte:3.2.5"

Usage

The starter configures a org.springframework.web.servlet.ViewResolver and a jte Template engine. Now you can return a string, pointing to template file name and the resolver will take care to instantiate the view and render the template.

Info

By default, the templates are expected at src/main/jte.

1
2
3
4
5
@import com.example.demo.DemoModel

@param DemoModel model

Hello ${model.text}!
1
2
3
4
5
@GetMapping("/") 
public String view(Model model, HttpServletResponse response) {
    model.addAttribute("model", new DemoModel("Hello World"));
    return "demo";
}

You can use it with Spring WebMVC as well as with Spring WebFlux.

Configuration

By default, the template files are expected in src/main/jte, You can also set the templateSuffix of your jte templates

gg.jte.templateLocation=src/main/jte
gg.jte.templateSuffix=.jte

Development

If you set developmentMode = true the jte file watcher will watch for changes in templates and recompile them.

Warning

This only works with a JDK!

gg.jte.developmentMode=true

Runtime-compiled templates are written to jte-classes relative to the application's working directory by default. In the Spring Boot 3 starter, you can set gg.jte.class-directory to an absolute or relative path:

gg.jte.class-directory=target/jte-classes

This setting applies to runtime compilation in both Spring WebMVC and WebFlux. It does not configure the Maven or Gradle plugin's precompiled output.

In development mode, you can also set trimControlStructures = true which will trim control structures.

gg.jte.trimControlStructures=true

Production

To use precompiled Templates in production, for use with a JRE environment, you need to configure the Maven/Gradle Plugin to precompile your templates:

gg.jte.usePrecompiledTemplates=true