Spring Boot + IntelliJ IDEA——自动部署[Spring Boot热部署]+LiveReload[前端自动刷新、热加载]解决方案
基本概念
spring-boot-devtools:?Spring Boot包括一組額外的工具,這些工具可以使應用程序開發體驗更加愉快。該spring-boot-devtools模塊可以包含在任何項目中,以提供其他開發時功能。
LiveReload:An implementation of the LiveReload server in Node.js. It's an alternative to the graphical?http://livereload.com/?application, which monitors files for changes and reloads your web browser.
官方文檔
spring-boot-devtools?
https://docs.spring.io/spring-boot/docs/2.2.4.RELEASE/reference/htmlsingle/#using-boot-devtools
LiveReload
https://docs.spring.io/spring-boot/docs/2.2.4.RELEASE/reference/htmlsingle/#using-boot-devtools-livereload
http://livereload.com/extensions/?
Maven
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional></dependency> </dependencies>Gradle
configurations {developmentOnlyruntimeClasspath {extendsFrom developmentOnly} } dependencies {developmentOnly("org.springframework.boot:spring-boot-devtools") }?注:
在運行完全打包的應用程序時,開發工具會自動被禁用,如果您的應用程序是從java -jar啟動的,或者是從一個特殊的類加載器開始的,那么它就被認為是一個“生產應用程序”。將依賴項標記為Maven中的可選項<optional>true</optional>或在Gradle中使用compileOnly是一種最佳實踐,它可以防止devtools被傳遞到其他使用你的項目的模塊中。
解決方案
?spring-boot-devtools?配置過程
1、添加Maven或者Gradle依賴
2、修改IntelliJ IDEA?Settings自動編譯
File --> Settings --> Compiler --> Build Project automatically
3、允許APP運行時自動構建?
Ctrl + Shift + Alt + / --> Registry --> 勾選Compiler autoMake allow when app running?
?LiveReload 配置過程
1、?spring-boot-devtools模塊包括一個嵌入式LiveReload服務器
2、從livereload.com免費獲得適用于Chrome,Firefox和Safari的LiveReload瀏覽器擴展。
3、安裝瀏覽器擴展
?4、啟用瀏覽器擴展
當瀏覽器擴展圖標中間圓點空心時,熱加載沒有啟用
點了它一下,變成黑色實心即可。?
注:如果多次點擊無效,說明LiveReload服務器未開啟。
5、保存(Ctrl + S)文件以后,前端頁面自動刷新。
注:
一次只能運行一臺LiveReload服務器。在啟動應用程序之前,請確保沒有其他LiveReload服務器正在運行。如果從IDE啟動多個應用程序,則只有第一個具有LiveReload支持。
教學資源
https://www.bilibili.com/video/av65117012/?p=25
常見問題
Spring Boot——[Unable to start LiveReload server]解決方案
參考文章?
https://www.jianshu.com/p/99f17c7e12f5
https://my.oschina.net/u/3939059/blog/2252395
https://www.cnblogs.com/zcynine/p/5559794.html
總結
以上是生活随笔為你收集整理的Spring Boot + IntelliJ IDEA——自动部署[Spring Boot热部署]+LiveReload[前端自动刷新、热加载]解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring Boot——MyBatis
- 下一篇: Thymeleaf——在不覆盖现有cla