【发布时间】:2016-05-14 01:22:22
【问题描述】:
我正在使用带有 gradle 插件的 Spring Boot 1.3.2。在我的多部分项目中,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 :web-admin:bootRun
更新/回答:
在网上冲浪和阅读 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
}
【问题讨论】:
-
这与我的设置(使用 Maven 在 Eclipse 中运行)有很大不同,我不确定细节,但请检查您的应用程序是否从打包的 jar 中提供文件,而不是从开发类路径。
-
检查更新。发现了一招。
-
如果这为您解决了问题,请将其作为答案发布并接受。
-
发了,我接受不了。
-
有一个最短时间;大约一天后就可以使用了。
标签: java spring gradle spring-boot jetty