intellij-idea - 如何在 Spring Boot 1.3 中启用 Thymeleaf Live Reloading

标签 intellij-idea gradle spring-boot thymeleaf

我创建了一个使用 Thymeleaf 的 Spring Boot Gradle 项目。我的 IDE 是 IntelliJ。我在根文件夹中创建了一个 application.properties :

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

但不知何故,它仍然没有自动重新加载。我必须先点击“制作项目”按钮。我有另一个项目,具有相同的配置(不确定 IntelliJ 设置),奇怪的是,它可以在刷新时工作。

我的 application.properties 正在被读取,因为我可以使用 @Value 注释提取自定义属性。

作为引用,我的 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'
}

想法?

最佳答案

根据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 依赖 src/main/resources被添加到类路径 不管 如果您正在使用 spring-boot-devtools。幸运的是, 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-loaded 最终将被弃用,取而代之的是 spring-boot-devtools。动态热交换在 Spring 中似乎是一件复杂的事情,我认为 Spring 团队已经决定像 devtools 使用的那样在快速重新加载的基础上工作。

关于intellij-idea - 如何在 Spring Boot 1.3 中启用 Thymeleaf Live Reloading,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34655114/

相关文章:

spring - 从 IntelliJ 运行时如何激活 Spring Boot 配置文件?

java - IntelliJ 无法识别来自 gradle 项目的某些导入

gradle - 无法在数据中心框架 MarkLogic 中运行 Harmonize 流

java - 如何在 Spring Boot 3/Hibernate 6 中使用查询参数值记录 SQL 语句

spring-boot - 实体不持久。 RepositoryItemWriter 和 SimpleJpaWriter 线程安全吗?

java - Maven 3 构建扩展和 IntelliJ Idea

keyboard-shortcuts - 创建局部变量的 IntelliJ 快捷方式是什么?

spring - 在Spring Boot中无法获取系统变量

java - 如何在没有 jar 依赖的 Gradle 中创建共享项目

spring-boot - 尝试访问节点类型(用户)上不存在的字段(上下文)