Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot: hot swapping does not work

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
    }
like image 520
Lugaru Avatar asked Jan 06 '23 17:01

Lugaru


2 Answers

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
}
like image 114
Lugaru Avatar answered Jan 16 '23 19:01

Lugaru


I had the same issue and i resolved it by setting spring.thymeleaf.cache in the application properties to false

How to Fix

Add spring.thymeleaf.cache=false in your application.properties file

like image 36
Abdullah Khan Avatar answered Jan 16 '23 18:01

Abdullah Khan