1 pom.xml文件
注:熱部署功能spring-boot-1.3開始有的
1
2
3
4
5
6
7
|
<!--添加依賴--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <!-- optional= true ,依賴不會傳遞,該項目依賴devtools;之后依賴myboot項目的項目如果想要使用devtools,需要重新引入 --> <optional> true </optional> </dependency> |
注:project 中添加 spring-boot-maven-plugin,主要在eclipse中使用,idea中不需要添加此配置。
1
2
3
4
5
6
7
8
9
10
11
|
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork> true </fork> </configuration> </plugin> </plugins> </build> |
2 更改idea配置
1) “File” -> “Settings” -> “Build,Execution,Deplyment” -> “Compiler”,選中打勾 “Build project automatically” 。
2) 組合鍵:“Shift+Ctrl+Alt+/” ,選擇 “Registry” ,選中打勾 “compiler.automake.allow.when.app.running” 。
3 Chrome禁用緩存
F12或者“Ctrl+Shift+I”,打開開發者工具,“Network” 選項卡下 選中打勾 “Disable Cache(while DevTools is open)”
補充:
Intellij IDEA 4種配置熱部署的方法
熱部署可以使的修改代碼后,無須重啟服務器,就可以加載更改的代碼。
第1種:修改服務器配置,使得IDEA窗口失去焦點時,更新類和資源
菜單Run -> EditConfiguration , 然后配置指定服務器下,右側server標簽下on frame deactivation = Update classes and resource。
優點:簡單
缺點:基于JVM提供的熱加載僅支持方法塊內代碼修改,只有debug模式下,并且是在idea失去焦點時才會出發熱加載,相對加載速度緩慢
第2種:使用springloaded jar包
a. 下載jar包,github:https://github.com/spring-projects/spring-loaded
b. 啟動應用時添加VM啟動參數:-javaagent:/home/lkqm/.m2/repository/org/springframework/springloaded/1.2.7.RELEASE/springloaded-1.2.7.RELEASE.jar -noverify
優點:對Spring系列框架支持好(不含Spring boot), 支持 成員級別的修改(增刪改方法、字段、注解),支持對枚舉值集。
缺點:與優點相對
第3種:使用spring-boot-devtools提供的開發者工具
spring-boot項目中引入如下依賴
1
2
3
4
|
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> |
優點:簡單,支持Spring-boot項目,支持成員級別的修改熱部署。
缺點:只支持spring-boot項目。
第4種:使用Jrebel插件實現熱部署(該插件14天免費試用)
在線安裝:菜單File -> Setting -> Plugin, 點擊右側底部 Browse repositories, 彈出框頂部輸入:JReble for Intellij, 選中安裝即可。
優點:強大,對各類框架支持,并且提供IDE插件的方式。
最后3種方法是基于類加載機制來實現熱加載的,因此你修改完成代碼后必須重新編譯當前代碼,才能觸發熱部署,Eclipse默認就支持了自動編譯,而在Intellij IDEA中默認是關閉了自動編譯的,可以按照如下2步設置開啟:
- IDEA開啟項目自動編譯,進入設置,Build,Execut, Deployment -> Compiler 勾選中左側的Build Project automatically
- IDEA開啟項目運行時自動make, ctrl + shift + a搜索命令:registry -> 勾選compiler.automake.allow.when.app.running
總結
以上所述是小編給大家介紹的Springboot在IDEA熱部署的配置方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
原文鏈接:https://blog.csdn.net/zn65786412qq/article/details/79899946