Skip to content

Spring Boot 2 Starter

This starter is compatible with Spring Boot 2.x!

Add required dependencies

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

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. If any active profile is named prod the template engine will be configured to use precompiled templates otherwise the jte file watcher will watch for changes in templates and recompile them.

Both options can be changed via

gg.jte.productionProfileName=k8s
gg.jte.templateLocation=src/main/templates