Spring Boot: hot swapping does not work

Refresh

November 2018

Views

3.1k time

4

I'm using Spring Boot 1.3.2 with gradle plugin. In my multipart project hot swapping/reload for HTML/JS/CSS files does not work.

/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

In te projet also used: wro4j, thymeleaf, AngularJS

Part of 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")
}

Project executed with: gradle :web-admin:bootRun

Update/Answer:

After some surfing in internet and reading spring-boot docs I found one trick. Problem in using devtools together with spring-boot-gradle-plugin as a result I simply need to add to my gradle.build file few lines:

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

2 answers

5

После некоторого серфинга в интернете и чтения пружинно-загрузочные документы я нашел один трюк. Проблема в использовании DevTools вместе с пружинными загрузки Gradle-плагин в результате я просто нужно добавить в мой gradle.build файлов несколько строк:

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

У меня была такая же проблема , и я разрешил ее, установив spring.thymeleaf.cacheв свойствах приложения кfalse

Как исправить

Добавить spring.thymeleaf.cache=falseв вашем application.propertiesфайле