1、新建SpringBoot项目

环境准备

  • JDK 1.8
  • SpringBoot2.2.1
  • Maven 3.2+
  • 开发工具
  • smartGit
  • IntelliJ IDEA2018

创建一个SpringBoot Initialize项目,详情可以参考我之前博客:SpringBoot系列之快速创建项目教程

SpringBoot系列之IDEA项目中设置热部署教程_ide

在这里插入图片描述


检查spring-boot-devtools是否加上?

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>

ps:修改如下配置,reload才生效,​​<fork>true</fork>​​,用于明确表示编译版本配置有效

SpringBoot系列之IDEA项目中设置热部署教程_ide_02

在这里插入图片描述


补充:

如果有加上Thymeleaf模板引擎,需要关了Thymeleaf缓存,然后按Ctrl+F9重新编译,修改配置文件:

spring:
thymeleaf:
cache: false

2、IntelliJ IDEA配置

Settings->Build,Execut, Deployment -> Compiler,勾选中左侧的Build Project automatically


SpringBoot系列之IDEA项目中设置热部署教程_插入图片_03

在这里插入图片描述

Ctrl+Alt+Shift+/,选择Registry

SpringBoot系列之IDEA项目中设置热部署教程_spring_04

在这里插入图片描述


勾选complier.automake.allow.when.app.running


SpringBoot系列之IDEA项目中设置热部署教程_ide_05

在这里插入图片描述

ok,next需要重启 IntelliJ IDEA,既可实现java文件自动构建,不过对于html还是要按Ctrl+F9编译

代码例子下载:​​code download​