<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork><!--必須添加這個配置-->
</configuration>
</plugin>
</plugins>
</build>
主要的原因還是<fork>的配置,下面是原文鏈接,可以參考下
https://blog.csdn.net/weixin_43599678/article/details/86777101
porm文件添加依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
idea設置

Shift+Ctrl+Alt+/,選擇Registry
選 compiler.automake.allow.when.app.running

之后重啟idea就可以了

