只要在pom文件中添加下面代码段即可
<!--使用热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<!-- optional=true, 依赖不会传递, 该项目依赖devtools;
之后依赖boot项目的项目如果想要使用devtools, 需要重新引入 -->
<optional>true</optional>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 没有该配置,devtools 不生效 -->
<configuration>
<fork>true</fork>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>
但是配置好无效,下面需要修改idea中的两个配置
setting –> compiler
将 Build project automatically 勾选上
alt + shift + a (command+shift+alt+/(mac系统))搜索 registry 选第一个,弹出框后下拉找到 compiler.automake.allow.when.app.running 勾选上即可。