如何在Spring Boot 1.3中启用Thymeleaf Live Reloading [英] How do I enable Thymeleaf Live Reloading in Spring Boot 1.3

查看:157
本文介绍了如何在Spring Boot 1.3中启用Thymeleaf Live Reloading的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用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'
}

想法?

解决方案

根据
$ b


Spring Boot Gradle插件不再添加 src / main / resources
直接到使用bootRun时的类路径。如果您想要直播,
就地编辑,我们推荐使用Devtools。如果要恢复Spring
Boot 1.2,可以在gradle build中设置addResources
属性。行为。

Thymeleaf依靠将 src / main / resources 添加到无论是否使用spring-boot-devtools,不管是否使用classpath 。幸运的是,spring-boot-devtools确实有一个选项可以打开它来恢复引导1.2行为。



添加到您的build.gradle:



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

  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:

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.

这篇关于如何在Spring Boot 1.3中启用Thymeleaf Live Reloading的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆