- • Quickstart
- • Documentation
- • Documentation DevOps
- • Next Steps
- • Spring Boot
- • Spring Data
- • Spring Data MongoDB
- • Spring Security
- › Frontend
- • Multi-Module
Last updated: 2022-11-02
Hot Reload of Thymeleaf Templates during development
Did you know that you can save days or weeks of development time when starting new Spring Boot apps? br With Bootify you have the right helper at your side - get a runnable prototype in minutes and focus on your business logic instead. Best practices included.
Frontend development involves frequent changes to the HTML code, the effects of which you want to see in the browser immediately. In order to always use the current template during development, a small extension of the code is necessary.
By default a Spring Boot application will load Thymeleaf templates from the classpath. For the bundled application this also makes a lot of sense, however during development every modified file has to be recompiled first to see the change. Even disabling the cache with
spring.thymeleaf.cache=false cannot alter this behavior.
With the following configuration, which only becomes active for the profile
local, the templates are loaded directly from the file system.
Configuration for hot swapping of Thymeleaf templates
A little bit of magic is needed here right at the beginning of our method: we first locate the file
application.properties from the classpath, so that we have an anchor in the file system. From there we go up until we find the highest level of our project by looking for the file
With this information we can configure our
FileTemplateResolver and set it to the TemplateEngine. All changes to the Thymeleaf templates are now immediately visible in the browser - hot swapping is now active. Don't forget the add the required profile during development, for example with a parameter
If we work with Webpack and the DevServer, it can also be configured to watch HTML files. With this setup the browser will reload itself automatically after each change - no active page reload needed anymore.
Part of webpack.config.js to observe HTML files
With Bootify, modern Spring Boot applications with their own database schema, CRUD functions and advanced features can be initialized directly in the browser. In the Free Plan a frontend based on Thymeleaf can be selected, with which the
LocalDevConfig is directly available - matching the selected setup for Yaml or Properties and the build type.
No registration required