Spring 引导:热插拔不起作用

Spring Boot: hot swapping does not work

我正在使用带有 gradle 插件的 Spring Boot 1.3.2。在我的多部分项目中,HTML/JS/CSS 文件的热 swapping/reload 不起作用。

/resources
  |-wro.groovy
  |-application.yml
  |-/templates/(all *.html files and index.html)
  |-/static/
      |-/js/
      |-/css/

application.yml

server:
 port: 8080

spring:
  thymeleaf:
    cache: false
    prefix: classpath:/templates/
    suffix: .html
    enabled: true
    encoding: UTF-8
    mode: HTML5

在项目中还使用了:wro4j、thymeleaf、AngularJS

gradle.build

的一部分
buildscript {
    ext { springBootVersion = '1.3.2.RELEASE' }
    repositories {
        maven {
            url "https://ourartifactoryUrl/plugins-release"
            credentials {
                // artifactory log and pass
            }
        }
    }
    dependencies {
        classpath group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: springBootVersion
        classpath group: 'io.spring.gradle', name: 'dependency-management-plugin', version: '0.5.2.RELEASE'
        classpath group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.1.+'
        classpath 'org.springframework.build.gradle:propdeps-plugin:0.0.7'

    }
}

apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'idea'
apply plugin: 'application'
apply plugin: 'propdeps'
apply plugin: 'propdeps-maven'
apply plugin: 'propdeps-idea'
apply plugin: 'propdeps-eclipse'


...


dependencies {
   compile('org.springframework.boot:spring-boot-starter-web')
   compile("org.springframework.boot:spring-boot-starter-thymeleaf")
   compile("org.springframework.boot:spring-boot-starter-jetty")
   compile("org.springframework.boot:spring-boot-starter-actuator")
   compile("org.springframework.boot:spring-boot-starter-redis")
   compile("org.springframework.boot:spring-boot-devtools")
}

项目执行:gradle :web-admin:bootRun

Update/Answer:

在网上冲浪并阅读 spring-boot 文档后,我发现了一个技巧。 使用 devtools together with spring-boot-gradle-plugin 的问题结果我只需要在我的 gradle.build 文件中添加几行:

    // Used by 'Spring Boot Gradle Plugin' in combination with 'Devtools' makes HTML/JS/CSS reloadable.
    bootRun {
        addResources = true
    }

在网上冲浪并阅读 spring-boot 文档后,我发现了一个技巧。将 devtools 与 spring-boot-gradle-plugin 一起使用时出现问题,因此我只需要在我的 gradle.build 文件中添加几行:

// Used by 'Spring Boot Gradle Plugin' in combination with 'Devtools' makes HTML/JS/CSS reloadable.
bootRun {
    addResources = true
}

我遇到了同样的问题,我通过将应用程序属性中的 spring.thymeleaf.cache 设置为 false

解决了这个问题

How to Fix

在您的 application.properties 文件中添加 spring.thymeleaf.cache=false