1. 程式人生 > 程式設計 >SpringBoot在IDEA中實現熱部署的步驟

SpringBoot在IDEA中實現熱部署的步驟

IDEA版本:2020.3

具體步驟

一、開啟IDEA的自動編譯【靜態】

1.File->Settings。
2.直接搜尋Compiler,選擇Build project automatically開啟自動編譯。

SpringBoot在IDEA中實現熱部署的步驟

二、開啟IDEA的自動編譯【動態】

1.同時按住 Ctrl + Shift + Alt + / 然後進入Registry ,勾選自動編譯並調整延時引數。

  • compiler.automake.allow.when.app.running -> 自動編譯
  • compile.document.save.trigger.delay -> 自動更新檔案,針對靜態資源,減少delay時間之後,直接按f5重新整理即可看到更新後頁面。

SpringBoot在IDEA中實現熱部署的步驟

三、開啟IDEA的熱部署策略【非常重要】

頂部選單Run- >Edit Configurations->SpringBoot外掛->目標專案->勾選熱更新。

SpringBoot在IDEA中實現熱部署的步驟

SpringBoot在IDEA中實現熱部署的步驟

四、在專案新增熱部署外掛(可選)

溫馨提示:
如果因為舊專案十分臃腫,導致每次都自動熱重啟很慢而影響開發效率,筆者建議直接在POM移除spring-boot-devtools依賴,然後使用Control+Shift+F9進行手工免啟動快速更新!!

具體步驟:在POM檔案新增熱部署外掛

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <scope>runtime</scope>
    </dependency>

五、關閉瀏覽器快取(重要)

開啟谷歌瀏覽器,開啟F12的Network選項欄,然後勾選【✅】Disable cache 。

SpringBoot在IDEA中實現熱部署的步驟

六、補充

如果使用的Thymleaf,一定記得配置:

spring:
 thymeleaf:
  cache: false

作者:天喬巴夏丶
出處:https://www.cnblogs.com/summerday152/
本文已收錄至Gitee:https://gitee.com/tqbx/JavaBlog
若有興趣,可以來參觀本人的個人小站:https://www.hyhwky.com

以上就是SpringBoot在IDEA中實現熱部署的步驟的詳細內容,更多關於SpringBoot 熱部署的資料請關注我們其它相關文章!