Spring Boot實現熱載入(Eclipse,IDEA)
阿新 • • 發佈:2019-01-26
步驟很簡單,只需要變更一下pom檔案。
1. Maven新增依賴
將下邊的依賴新增到你的pom檔案中去
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies >
2. 實現熱載入
- 在Eclipse中,儲存檔案會自動觸發熱載入
- 在IDEA中,需要build project來觸發熱載入,快捷鍵是Ctrl+F9
官方文件:As DevTools monitors classpath resources, the only way to trigger a restart is to update the classpath. The way in which you cause the classpath to be updated depends on the IDE that you are using. In Eclipse, saving a modified file causes the classpath to be updated and triggers a restart. In IntelliJ IDEA, building the project (Build -> Build Project) has the same effect.
3. 注意
- 如果你的專案是通過java命令(java -jar)或者某個特殊的類載入器啟動的,spring-boot 的Developer tools會認為這是生產環境而自動失效