]> juplo.de Git - website/blob
1ec528be8c893e251d62ea0b84b02db3b7870e5d
[website] /
1 ---
2 _edit_last: "3"
3 author: kai
4 categories:
5   - java
6   - spring
7   - spring-boot
8   - thymeleaf
9 date: "2020-05-01T14:06:13+00:00"
10 guid: http://juplo.de/?p=543
11 parent_post_id: null
12 post_id: "543"
13 title: Fix Hot Reload of Thymeleaf-Templates In spring-boot:run
14 url: /fix-hot-reload-of-thymeleaf-templates-in-spring-bootrun/
15
16 ---
17 ## The Problem: Hot-Reload Of Thymeleaf-Templates Does Not Work, When The Application Is Run With `spring-boot:run`
18
19 A lot of people seem to have problems with hot reloading of static HTML-ressources when developing a [Spring-Boot](http://projects.spring.io/spring-boot/#quick-start "Learn more about Spring-Boot") application that uses [Thymeleaf](http://www.thymeleaf.org/ "Learn more about Thymeleaf") as templateing engine with [`spring-boot:run`](http://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html "Learn more about the spring-boot-maven-plugin").
20 There are a lot of tips out there, how to fix that problem:
21
22 - [The official Hot-Swapping-Guide](http://docs.spring.io/spring-boot/docs/current/reference/html/howto-hotswapping.html "Read the official guide") says, that you just have to add `spring.thymeleaf.cache=false` in your application-configuration in `src/main/resources/application.properties`.
23 - [Some say](http://stackoverflow.com/a/26562302/247276 "Read the whole suggestion"), that you have to disable caching by setting `spring.template.cache=false` **and** `spring.thymeleaf.cache=false` and/or run the application in debugging mode.
24 - [Others say](http://stackoverflow.com/a/31641587/247276 "Read the suggestion"), that you have to add a dependency to `org.springframework:springloaded` to the configuration of the `spring-boot-maven-plugin`.
25 - There is even a [bug-report on GitHub](https://github.com/spring-projects/spring-boot/issues/34 "Read the whole bug-report on GitHub"), that says, that you have to run the application from your favored IDE.
26
27 But none of that fixes worked for me.
28 Some may work, if I would switch my IDE (I am using Netbeans), but I have not tested that, because I am not willing to switch my beloved IDE because of that issue.
29
30 ## The Solution: Move Your Thymeleaf-Templates Back To `src/main/webapp`
31
32 Fortunatly, I found a simple solution, to fix the issue without all the above stuff.
33 **You simply have to move your Thymeleaf-Templates back to where they belong (IMHO): `src/main/webapp` and turn of the caching.**
34 It is not necessary to run the application in debugging mode and/or from your IDE, nor is it necessary to add the dependency to `springloaded` or more configuration-switches.
35
36 To move the templates and disable caching, just add the following to your application configuration in `src/main/application.properties`:
37
38 ```properties
39 spring.thymeleaf.prefix=/thymeleaf/
40 spring.thymeleaf.cache=false
41
42 ```
43
44 Of course, you also have to move your Thymeaf-Templates from `src/main/resources/templates/` to `src/main/webapp/thymeleaf/`.
45 In my opinion, the templates belong there anyway, in order to have them accessible as normal static HTML(5)-files.
46 If they are locked away in the classpath you cannot access them, which foils the approach of Thymeleaf, that you can view your templates in a browser as thy are.
47
48 ## Funded by the Europian Union
49
50 This article was published in the course of a
51 [resarch-project](http://yourshouter.com/projekte/crowdgest%C3%BCtzte-veranstaltungs-suchmaschine.html "Show details about the funded resarch-project"),
52 that is funded by the European Union and the federal state Northrhine-Wetphalia.
53
54 [![Europäische Union: Investitionen in unsere Zukunft - Europäischer Fonds für regionale Entwicklung](/img/EFRE_Foerderhinweis_deutsch_farbig.svg)![EFRE.NRW 2014-2020: Invesitionen in Wachstum und Beschäftigung](/img/Ziel2NRW_4c_1809_eps.svg)](http://yourshouter.com/projekte/crowdgest%C3%BCtzte-veranstaltungs-suchmaschine.html "Show details about the funded resarch-project")