相信很多人自己百度“idea springboot 熱部署”
,找到的解決方案都是如下:
1.項目加入依賴spring-boot-devtools
2.idea按ctrl+alt+s
——build,excution,deployment
——compiler
——勾選build project automatically
3.idea按ctrl+shift+a
——輸入registry
——compiler
——勾選compiler.automake.allow.when.app.running
但其實這樣設置,每次你改一點點代碼,都會觸發(fā)idea重新編譯,idea變得很卡,開發(fā)體驗不好。
其實idea提供了對spring-boot-devtools
的相應支持的,打開idea——help
在彈出網(wǎng)頁中輸入spring boot
,就能找到configure application update policies with devtools這篇文檔。
實際操作:
1.在你的spring boot項目中引入依賴spring-boot-devtools
2.找到main方法,運行一下項目。注意一定要通過點擊main方法運行
,而不能是通過mvn spring-boot:run
或gradle bootrun
,如下圖:
3.運行后我們就可以打開run
——edit configurations
,在springboot
下設置on update action
為update classes and resources
,如下圖:
4.設置后,通過main方法運行,或者在菜單欄點擊run圖標運行,如圖:
5.當我們修改完代碼后,idea不會自動編譯重新啟動springboot,而是我們需要按一下左下角的run
欄目中的update xxx application
才會觸發(fā)熱切換。當然我們也可以用快捷鍵ctrl+f10
。如下圖:
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://segmentfault.com/a/1190000015930347