1、引入jar:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>provided</scope>
<!-- optional=true, 依賴不會傳遞, 該項目依賴devtools;
之後依賴boot項目的項目如果想要使用devtools, 需要重新引入 -->
<optional>true</optional>
</dependency>
2、在yml文件上配如下:
spring:
devtools:
restart:
enabled: true #設置開啓熱部署
3、設置idea運行前自動編譯:【ctrl + shift + alt + /,選擇Registry,勾上 Compiler autoMake allow when app running】
4、編譯插件:設置 fork 爲 true
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>