热部署的原理是在发现代码有更改后会立即重启应用,但这个速度比手动停止后再启动要快。重启应用的时机发生在保存代码的时候。
一、实现热部署的步骤
1、开启自动编译
1、点击file -->点击settings -->展开 build,execution,deployment -->点击compiler -->勾选 build project automatically -->点击ok
2、Ctrl+Shift+A -->registry -->勾选compiler.automake.allow.when.app.running
3、重启idea
2、添加devtools依赖
1、在pom.xml中添加devtools依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
<scope>runtime</scope>
</dependency>
2、在pom.xm