1.在pom文件中添加 devtools 依赖
<!-- 实现热部署的依赖 devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 如果不填加这项,热部署不生效-->
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
2.我用的idea,设置自动编译
File - Setting - Build - Compiler 下的Build Project automatically 打钩
3.IDEA开启自动编译在程序运行时
CTRL + SHIFT + A --> 查找Registry --> 找到compiler.automake.allow.when.app.running --> 勾选
4.最后重启IDEA,热部署就成功了。如果不重启,同样的路径访问会报404找不到的