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