在pom.xml中加入如下配置即可。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
注意以下的熱部署方式在IDEA是默認沒有打開自動編譯的,手動編譯需要快捷鍵(Ctrl+Shift+F9),自動編譯的修改配置如下:(注意刷新不要太快,會有1-2秒延遲)
File-Settings-Compiler-Build Project automatically
最後打開Ctrl+Shift+Alt+/
選擇Registry
勾選compiler.automake.allow.when.app.running