How to enable Thymeleaf Live Reloading in Spring Boot 1.3

I created a Spring Boot Gradle project that uses Thymeleaf. My IDE is IntelliJ. I created the application.properties application in the root folder with:

spring.resources.cache-period=0 spring.thymeleaf.cache=false spring.thymeleaf.mode=LEGACYHTML5 

But for some reason this is not autoload yet. First I have to click the "Make Project" button. I have another project with the same configuration (not sure about IntelliJ settings), which, oddly enough, works when upgrading.

My .properties applications are being read since I can pull out a custom property using the @Value annotation.

For reference, my build.gradle

 buildscript { ext { springBootVersion = '1.3.1.RELEASE' } repositories { mavenCentral() jcenter() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") classpath("org.springframework:springloaded:1.2.5.RELEASE") } } apply plugin: 'spring-boot' apply plugin: 'java' apply plugin: 'idea' sourceCompatibility = 1.8 targetCompatibility = 1.8 idea { module { inheritOutputDirs = false outputDir = file("$buildDir/classes/main/") } } jar { baseName = 'earthalive' version = "" } repositories { mavenCentral() } dependencies { compile('org.springframework.boot:spring-boot-starter-web') compile('org.springframework.boot:spring-boot-starter-thymeleaf') testCompile('org.springframework.boot:spring-boot-starter-test') compile('net.sourceforge.nekohtml:nekohtml:1.9.22') } task wrapper(type: Wrapper) { gradleVersion = '2.9' } 

Ideas?

+5
source share
3 answers

According to Spring Boot 1.3 release documentation :

The Spring Boot Gradle plugin no longer adds src/main/resources directly to the classpath when using bootRun. If you want to live, in-place editing we recommend using Devtools. Additional resource property can be set in the Gradle assembly if you want to restore Spring. Download 1.2. behavior.

Thymeleaf relies on src/main/resources added to the classpath regardless if you use spring-boot-devtools or not. Fortunately, spring-boot-devtools has the ability to enable this again to restore 1.2 loading behavior.

Add to your build.gradle file:

https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html

 bootRun { addResources = true } 

Personal opinion: it seems to me that spring -loaded will eventually be deprecated in favor of spring-boot-devtools. Dynamic hotswapping seems to be tricky in Spring, and I think the Spring team decided to work faster with a quick reload, as devtools is used.

+6
source

Since you are using 1.3 from Spring boot - perhaps another project uses devtools - which automatically updates springBoot applications:

 compile 'org.springframework.boot:spring-boot-devtools' 

spring-boot-devtools is what makes working with Thymeleaf great for me - in combination with the chrome / firefox Live Reload extension, you don’t even have to update your browser. Spring docs

 dependencies { compile 'org.springframework.boot:spring-boot-devtools' compile('org.springframework.boot:spring-boot-starter-web') compile('org.springframework.boot:spring-boot-starter-thymeleaf') testCompile('org.springframework.boot:spring-boot-starter-test') compile('net.sourceforge.nekohtml:nekohtml:1.9.22') } 
+1
source

Eclipse will automatically compile the project upon saving. IntelliJ does not. The compilation action is what causes the reboot. Which, as an IntelliJ user, I find annoying.

I looked at devtools and rebooted on my blog here: https://springframework.guru/spring-boot-developer-tools/

+1
source

Source: https://habr.com/ru/post/1240087/


All Articles