Reputation: 13519
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?
Upvotes: 7
Views: 7833
Reputation: 13519
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.
Upvotes: 6
Reputation: 524
Eclipse will automatically compile the project upon save. IntelliJ does not. The compile action is what triggers the reload. Which, as an IntelliJ user I find annoying.
I did a review of the devtools and reloading on my blog here: https://springframework.guru/spring-boot-developer-tools/
Upvotes: 1
Reputation: 13571
Since you are using 1.3 of Spring boot - perhaps the other project is using the devtools - which auto refreshes springBoot apps:
compile 'org.springframework.boot:spring-boot-devtools'
spring-boot-devtools is what makes working with Thymeleaf great for me - in conjunction with Live Reload chrome/firefox extension you won't even have to refresh your browser either. 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')
}
Upvotes: 1