Spring Boot:热部署无法工作

4

我正在使用Spring Boot 1.3.2和gradle插件。我的多部分项目中,HTML/JS/CSS文件的热交换/重新加载不起作用。

/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执行项目:gradle :web-admin:bootRun

更新/回答:

在网上搜索并阅读spring-boot文档后,我发现了一个技巧。使用devtoolsspring-boot-gradle-plugin时出现的问题是,我只需要在我的gradle.build文件中添加几行代码:

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

这个设置与我的设定有所不同(在Eclipse和Maven中运行),细节我不确定,但请检查您的应用程序是否将文件从打包的jar文件中提供而不是从开发类路径中提供。 - chrylis -cautiouslyoptimistic-
检查更新。发现一个技巧。 - Lugaru
如果这个解决方案对您有用,请将其发布为答案并接受它。 - chrylis -cautiouslyoptimistic-
发布了,但我不能接受它。 - Lugaru
有一个最短时间;它将在大约一天后可用。 - chrylis -cautiouslyoptimistic-
2个回答

6

在浏览互联网并阅读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
}

在我的情况下,像Gradle插件-6.2重新加载资源中提到的sourceResources sourceSets.main是有帮助的。 - Jazzschmidt

3

我曾经遇到过同样的问题,通过在应用程序属性中将spring.thymeleaf.cache设置为false来解决了这个问题。

如何解决

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接