IDEA 熱部署- 自動編譯設定 spring boot 熱部署devtools實現
原文:https://www.cnblogs.com/TechSnail/p/7690829.html && https://blog.csdn.net/qq_31293575/article/details/80654132
擴充套件:
https://blog.csdn.net/diaomeng11/article/details/73826564
https://blog.csdn.net/z15732621582/article/details/79439359 : bean.xml配置的專案
===前言===start==========================================================
spring boot 熱部署devtools實現
1.devtools
spring為開發者提供了一個名為spring-boot-devtools的模組來使Spring Boot應用支援熱部署,提高開發者的開發效率,無需手動重啟Spring Boot應用。
2.專案搭建
本文是採用IDEA搭建的Spring Boot應用,通過spring-boot-devtools配置,可以支援修改java檔案會自動重啟程式,一些資源無需觸發重啟,例如thymeleaf模板檔案就可以實時編輯。預設情況下,更改/META-INF/maven,/META-INF/resources ,/resources ,/static ,/public 或/templates下的資源不會觸發重啟,而是觸發livereload。devtools模組包含一個嵌入的livereload伺服器,可以在資源變化時用來觸發瀏覽器重新整理。瀏覽器需要在livereload.com下載安裝擴充套件。 例如Chrome瀏覽器在應用商店安裝livereload外掛後,在要自動重新整理的頁面點選對應的圖示,啟動應用後更新頁面內容或者css等都會觸發頁面自動重新整理。
3.livereload
livereload 通過引入的指令碼livereload.js在 livereload 服務和瀏覽器之間建立了一個 WebSocket 連線。每當監測到檔案的變動,livereload 服務就會向瀏覽器傳送一個訊號,瀏覽器收到訊號後就重新整理頁面,實現了實時重新整理的效果。每次啟動時,需要點選對應的圖示,如下圖所示。
4.專案程式碼配置
(1)pom.xml配置檔案
1 2 3 4 5 6 7 8 9 10 11 12 |
<
dependency
>
<
groupId
>org.springframework.boot</
groupId
>
<
artifactId
>spring-boot-devtools</
artifactId
>
<
optional
>true</
optional
>
</
dependency
>
<
plugin
>
<
groupId
>org.springframework.boot</
groupId
>
<
artifactId
>spring-boot-maven-plugin</
artifactId
>
<
configuration
>
<
fork
>true</
fork
>
<!-- 如果沒有該配置,devtools不會生效 -->
</
configuration
>
</
plugin
>
|
(2)yml配置
1 2 3 4 5 6 |
devtools:
livereload:
enabled: true #是否支援livereload
port: 35729
restart:
enabled: true #是否支援熱部署
|
1.引入依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <!-- optional=true, 依賴不會傳遞, 該專案依賴devtools; 之後依賴boot專案的專案如果想要使用devtools, 需要重新引入 --> <optional>true</optional> </dependency>
===前言===end==========================================================
2.配置檔案
#開啟或者關閉freemarker和thymeleaf的頁面快取
spring.freemarker.cache=false
spring.thymeleaf.cache=true
spring.devtools.restart.enabled=true
#需要開啟熱部署的檔案目錄
spring.devtools.restart.additional-paths=src/main/java
#使用了mybatis好像需要設定,應該沒有必要。且生產環境需要移除
#restart.include.mapper=/mapper-[\\w-\\.]+jar
#restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar
#靜態檔案下不需要重啟
#spring.devtools.restart.exclude=static/**,public/**
#spring.devtools.restart.exclude=WEB-INF/**
3.更改idea配置
1) “File” -> “Settings” -> “Build,Execution,Deplyment” -> “Compiler”,選中打勾 “Build project automatically” 。
2) 組合鍵:“Shift+Ctrl+Alt+/” ,選擇 “Registry” ,選中打勾 “compiler.automake.allow.when.app.running”
4.Chrome禁用快取(如果還是無法使用)
F12或者“Ctrl+Shift+I”,開啟開發者工具,“Network” 選項卡下 選中打勾 “Disable Cache(while DevTools is open)”
1.devtools
spring為開發者提供了一個名為spring-boot-devtools的模組來使Spring Boot應用支援熱部署,提高開發者的開發效率,無需手動重啟Spring Boot應用。
2.專案搭建
本文是採用IDEA搭建的Spring Boot應用,通過spring-boot-devtools配置,可以支援修改java檔案會自動重啟程式,一些資源無需觸發重啟,例如thymeleaf模板檔案就可以實時編輯。預設情況下,更改/META-INF/maven,/META-INF/resources ,/resources ,/static ,/public 或/templates下的資源不會觸發重啟,而是觸發livereload。devtools模組包含一個嵌入的livereload伺服器,可以在資源變化時用來觸發瀏覽器重新整理。瀏覽器需要在livereload.com下載安裝擴充套件。 例如Chrome瀏覽器在應用商店安裝livereload外掛後,在要自動重新整理的頁面點選對應的圖示,啟動應用後更新頁面內容或者css等都會觸發頁面自動重新整理。
3.livereload
livereload 通過引入的指令碼livereload.js在 livereload 服務和瀏覽器之間建立了一個 WebSocket 連線。每當監測到檔案的變動,livereload 服務就會向瀏覽器傳送一個訊號,瀏覽器收到訊號後就重新整理頁面,實現了實時重新整理的效果。每次啟動時,需要點選對應的圖示,如下圖所示。
4.專案程式碼配置
(1)pom.xml配置檔案
1 2 3 4 5 6 7 8 9 10 11 12 |
<
dependency
>
<
groupId
>org.springframework.boot</
groupId
>
<
artifactId
>spring-boot-devtools</
artifactId
>
<
optional
>true</
optional
>
</
dependency
>
<
plugin
>
<
groupId
>org.springframework.boot</
groupId
>
<
artifactId
>spring-boot-maven-plugin</
artifactId
>
<
configuration
>
<
fork
>true</
fork
>
<!-- 如果沒有該配置,devtools不會生效 -->
</
configuration
>
</
plugin
>
|
(2)yml配置
1 2 3 4 5 6 |
devtools:
livereload:
enabled: true #是否支援livereload
port: 35729
restart:
enabled: true #是否支援熱部署
|