问题描述
我创建了一个使用Thymeleaf的Spring Boot Gradle项目。我的IDE是IntelliJ。我在根文件夹中创建了一个application.properties文件:
spring.resources.cache-period = 0
spring.thymeleaf.cache = false
spring.thymeleaf.mode = LEGACYHTML5
但以某种方式它仍然不会自动重新加载。我必须先点击Make Project按钮。我有另一个项目,具有相同的配置(不知道有关IntelliJ设置),奇怪的是,刷新工作。
我的application.properties被读为I可以使用@Value批注将一个自定义属性拉出来。
作为参考,我的build.gradle
<$ p $
$ b bcenter()
}
依赖关系{
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 = fi le($ buildDir / classes / main /)
}
}
jar {
baseName ='earthalive'
version =
存储库{
mavenCentral()
}
依赖项{
compile('org.springframework .boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
testCompile('org.springframework.boot:spring-boot ('net.sourceforge.nekohtml:nekohtml:1.9.22')
}
任务包装器(类型:包装器){
gradleVersion ='2.9'
}
想法?
根据
bootRun {
addResources = true
}
个人观点:在我看来,Spring加载最终会被弃用,而不是Spring-Boot-devtools。动态热门程序在Spring中似乎是一件复杂的事情,我认为Spring团队决定在devtools中使用快速重新加载的基础。
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?
According to the Spring Boot 1.3 release documentation:
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.
这篇关于如何在Spring Boot 1.3中启用Thymeleaf Live Reloading的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!