由于在开发Spring Boot工程过程中,会经常出现边开发边调测时需要修改部分内容,而如果反复的去启动项目,项目过大的话,会十分浪费时间,故此开发时,热部署显得很重要,效率也会大大提升。参见:IDEA热部署SpringBoot
1. 添加maven依赖
pom.xml文件中加入spring-boot-devtools依赖,如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>runtime</scope>
</dependency>
2. maven插件设置
需要在spring-boot-maven-plugin插件中配置参数:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>
3.编译设置
IDEA中 File->Settings->Build,Execution,Deployment->Compiler:中勾选Build project automatically,如下图:
4.运行设置
ctrl+shift+a 调起搜索,输入registry,点击第一项,打开Registry编辑框,找到compiler.automake.allow.when.
app.running
完成以上4步设置后,重启IDEA 即可。
注:亲自测试,发现spring-boot 2.2.x 版本不行,在2.0.x 版本可以。