I've created a Spring Boot Gradle project that uses Thymeleaf. My IDE is IntelliJ. I've created an application.properties in the root folder with:
spring.resources.cache-period=0
spring.thymeleaf.cache=false
spring.thymeleaf.mode=LEGACYHTML5
But somehow it's still not auto-reloading. I have to hit the "Make Project" button first. I have another project, with the same configuration (not sure about the IntelliJ settings) that strangely enough, does work on refresh.
My application.properties is being read as I can pull a custom property out 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?
Spring Boot will provide auto-configuration for Thymeleaf. Add spring-boot-starter-thymeleaf dependency in pom. xml to enable this auto-configuration. No other configurations required, Spring Boot will inject all required configuration to work with Thymeleaf.
Step-by-Step Guide. Run the application using mvn spring-boot:run (requires forking the JVM, which is the default mode) or via the Application class. Open the application in the browser, make some Java code changes, recompile, and the browser will refresh automatically.
The spring-boot-devtools module includes an embedded LiveReload server that can be used to trigger a browser refresh when a resource is changed. LiveReload browser extensions are freely available for Chrome, Firefox and Safari from livereload.com.
According to the 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 live, in-place editing we recommend using Devtools. The addResources property can be set in your gradle build if you want to restore Spring Boot 1.2. behaviour.
Thymeleaf relies on src/main/resources
being added to the classpath regardless if you're using spring-boot-devtools or not. Fortunately, spring-boot-devtools does have an option to turn this on again to restore boot 1.2 behaviour.
Add to your build.gradle:
https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html
bootRun {
addResources = true
}
Personal Opinion: It looks to me like Spring-loaded will eventually be deprecated in favour of spring-boot-devtools. Dynamic hotswapping seems to be a complex affair in Spring, and I think the Spring team has decided to rather work on a fast reload basis as is used by devtools.
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