Intellij IDEA Spring boot 静态文件自动加载热部署

IDE 2019-11-29 阅读 452 评论 0

使用 Intellij IDEA 开发 Spring boot,经常要编辑页面文件(html,js,css),每次编辑后,都要重新启动服务,比较繁琐,效率低。其实 Intellij IDEA 可以实现热部署。不用每次都重新启动服务。

1. Spring Boot Dev Tools

启用了Spring Boot Dev工具:

  • 对视图(views)或资源(resources)的任何更改都可以直接在浏览器中看到,无需重新启动,只需刷新浏览器。
  • java代码的任何更改,将自动重新启动Spring容器

引入 Spring Boot Dev Tools 依赖,在 build.gradle 添加

dependencies {
    compile("org.springframework.boot:spring-boot-devtools")    // 添加这一行
}

2. Build Project Automatically

  • windows 系统,点击 Intellij IDEA

File –> Setting –> Build, Execution, Deployment –> Compiler –>勾选 Build project automatically

  • mac 系统,点击 Intellij IDEA

Intellij IDEA -> Preferences -> Build, Execution, Deployment  –>勾选 Build project automatically

3. Intellij Registry

3.1 快捷键 SHIFT+CTRL+A (Windows/Linux) or Command+SHIFT+ALT+/ (Mac) 打开窗口, 搜索 registry

3.2 查找并启动选项 compiler.automake.allow.when.app.running

到此就完成了。


如果不会自动重启服务,或者自动热部署

点击菜单 -> Build -> Build Project  (windows CTRL + F9, mac  Command + F9 ) 强制重新启动

如果 thymeleaf 还不能自动部署,可以参考 使用gulp热部署spring boot的thymeleaf静态文件

最后更新 2019-12-02