Intellij+Springboot+Thymeleaf+gradle - 自动重载html资源

Posted

技术标签:

【中文标题】Intellij+Springboot+Thymeleaf+gradle - 自动重载html资源【英文标题】:Intellij+Springboot+Thymeleaf+gradle - autoreload html resources 【发布时间】:2017-09-10 04:23:38 【问题描述】:

我正在使用 IntelliJ Ultimate、Spring Boot 和 Thymeleaf。

我想在不重新启动服务器且不使用 CTRL-F9 的情况下启用 html 的自动重新加载。

我已经阅读了以下内容,我认为它应该可以工作,但事实并非如此:

https://github.com/spring-projects/spring-boot/issues/34

IntelliJ 15, SpringBoot devtools livereload not working

Livereload for assets in Intellij using Spring boot

我做了以下步骤:

build.gradle sn-p

compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: '1.5.2.RELEASE'
compile("org.springframework.boot:spring-boot-devtools")
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')


bootRun 
    addResources = true

编译器的 IntelliJ 设置:

和 Intellij 注册表设置:

我的 HTML 在 main\resources\templates 中,我的 application.properties\resources\

然后我尝试运行和调试项目,但无论哪种方式,我仍然必须在更改 HTML 之间重新构建 (CTRL-F9)。

从 snicoll 和 dsayer 读取 here 应该可以不使用 CTRL-F9:

【问题讨论】:

按照这里的一切,仍然无法正常工作。重新启动所有。 * Spring Boot 2.1.2.RELEASE * IntelliJ 2018.3.4 还有其他想法吗? 【参考方案1】:

添加注册表设置后出现:

compilier.automake.allow.when.app.running 

你不仅需要重启 Springboot 服务器,还需要重启 Intellij。

现在开始了。

【讨论】:

干得好@douggreaney【参考方案2】:

如果您仍在为spring-boot-devtools 苦恼,我建议您使用 Gulp 来自动化模板和资源重新加载。以下是一个对我来说很神奇的 Gulp 小任务:

var gulp = require('gulp'), 
watch = require('gulp-watch');

gulp.task('watch', function () 
    return watch('src/main/resources/**/*.*', () => 
        gulp.src('src/main/resources/**')
            //replace with build/resources/main/ for netBeans
            .pipe(gulp.dest('out/production/resources/')); 
    );
);

gulp.task('default', ['watch']);

我还就此主题写了一个简短的blog post,其中还包括其他方法。

【讨论】:

以上是关于Intellij+Springboot+Thymeleaf+gradle - 自动重载html资源的主要内容,如果未能解决你的问题,请参考以下文章

开源框架thyme-boot使用

thyme leaf中的Session username找不到,为null

为啥 html 元素中的 Html 文本不与 Thyme-leaf 文本连接?代码是[重复]

基于Springboot实现仓库管理系统

thyme leaf table便利数据跳转

springboot系列配置模板引擎配置热部署