When I change a thymeleaf .html file residing inside /templates , I expect the browser to automatically reload the page. I have the live reload plugin installed and its able to do a handshake with the spring boot server. However , upon chaning a thymeleaf template file , I have to manually reload the browser.
Any suggestions what I might be missing. Obviously I have spring-boot-devtools
enabled and have also manually updated the property devtools.livereload.enabled = true
. And spring devtools is correctly relecting changes to any template or controller in build target , and with a manual reload of browser , I see the changes.
As per spring docs.
Certain resources do not necessarily need to trigger a restart when they are changed. For example, Thymeleaf templates can be edited in-place. By default, changing resources in /META-INF/maven, /META-INF/resources, /resources, /static, /public, or /templates does not trigger a restart but does trigger a live reload.
I have my local running over a broken https. ( Some certificate issue , which causes a not secure
message in chrome address bar. Could this be the reason live reload is not working.
After 3 years of frustation here is a solution for a working HOT SWAP:
https://attacomsian.com/blog/spring-boot-auto-reload-thymeleaf-templates
Below are my tested settings (this is the only thing I've changed for it to work).
application.yaml
:
spring:
thymeleaf: # Thymeleaf
cache: false
mode: HTML
encoding: UTF-8
prefix: file:src/main/resources/templates/
resources: # Static resources
static-locations: file:src/main/resources/static/
cache:
period: 0
What it does:
static/
or templates/
What it does not:
This is all assuming you didn't override the default paths (/resources/templates
, /resources/static
).
P.S. I've tried with a self-signed TLS cert, it still works. Yes it won't behave like Angular with browser page reloading out of the box.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With