Last updated: 2025-07-30
Integrate jte with Spring Boot
Jte is a modern template engine for Spring Boot that stands out for its minimalist syntax. What steps are necessary to integrate jte into our application and make it ready for use in the real world?
The current sample code for the setup described is available here.
Application configuration
The starting point is a Spring Boot application based on Maven without a frontend. We can easily create this using Bootify with start project. We could already choose jte as the frontend, however we would like to manually review the exact steps involved.
First, we expand our pom.xml
with the following points.
New dependencies and plugin config for jte
This adds jte, Bootstrap as a WebJar and a Spring Boot starter that expects all templates to be located in src/main/jte
. To ensure that these are recompiled during development after every change, we add an application-local.properties
file with the following entries to our project.
During development, the local
profile should be active so that these settings are used. We extend the existing application.properties
with the following setting.
Precompiled templates are expected in the classpath with this setting - this is already handled by our configured plugin, which stores all artifacts in target/classes
so that they are integrated into our fat jar.
We need a helper to make further required functions available in our templates. To avoid having to define and pass an object as a parameter everywhere, we use a helper class with static methods.
Helper methods for our templates
The LocalizationSupport
is the recommended interface for internationalization. An interceptor is responsible for setting and removing the model for the duration of a request.
This allows us to use all defined functions in our templates using @import static io.bootify.jte.util.JteContext.*
and extend them as needed.
Layout and first pages
Real enterprise applications usually require a number of features that we want to integrate into our application. Firstly we want to add a layout.jte
. In abbreviated form, it looks like this - including a parameter content
, which we use to integrate the actual content of a template.
A simple jte layout
This allows us to continue with the actual pages. A file src/main/jte/error.jte
is automatically picked up by Spring Boot for error pages.
A simple error page
Here, we are using our prepared layout directly - the principle is clear. A homepage could look like this.
We have already completed all necessary steps so that our application compiles and displays jte templates.
More complex setups
The next step is to make our application support forms based on Spring MVC. There are no direct functions from jte for this - instead, we can extend our JteContext
class with practical helpers.
Extensions for form handling
The second variant of getFieldValue
is needed to obtain the value with its actual type. Jte templates are always compiled into real Java code, so casting may be necessary. Additional functions such as isAuthenticated()
for Spring Security can be added to JteContext
as needed.
Complete CRUD functionality and an inputRow.jte
template can be seen in the Spring Boot jte example.
Jte's minimalist approach is very appealing, especially if you are used to the complexity of Thymeleaf. Although you have to write your own helpers for some important features, the code is very easy to understand and extend.