1. 在Idea中配置自动build project
File >> Settings >> Build, Execution, Deployment >> Compiler >> 勾选 'Build project automatically', 点击OK保存
2. 快捷键ctrl + shift + alt + '/' 配置Registry
勾选compiler.automake.allow.when.app.running
3. 在pom中添加 spring-boot-devtools 依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>2.6.8</version>
</dependency>
在plugin下面添加configuration标签,设置fork为true
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>