熱啟動:修改代碼儲存時會自動重新啟動項目。
熱部署:動态替換你修改的class,效率會更高。
1:最簡單的就是對于idea使用ctrl+F9的方式可以實作熱部署:但是需要修改完不斷的按鍵,比較繁瑣。
2:熱啟動
SpringBoot的web項目,在每一次修改了java檔案或者是resource的時候,都必須去重新開機一下項目,這樣的話浪費了很多的時間,實作了熱啟動,在每一次作了修改之後,都會自動的重新開機
第一步:引入熱加載的插件,springboot 1.3開始就有的
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
project 中添加spring-boot-maven-plugin,主要在eclipse中起作用,idea不需要加此配置,springboot 項目的話,應該是有此配置,加裡面的内容即可。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
第二部 : idea設定(14版本)
1、點選: file ,Settings ,Build ,Execution,Deplment
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLi8CX05WZpJ3bt8Gd1F2LcJjcn9WTldWYtl2Pn5GcuMzYwQTZzIzM5YTZiFWOxYTL0czMxgTM58CXzV2Zh1WafRWYvxGc19CXvlmL1h2cuFWaq5ycldWYtlWLkF2bsBXdvw1LcpDc0RHaiojIsJye.png)
然後記得apply,ok。
2、組合鍵:Shift+ALT+Ctrl+/ ,選擇“Registry”,回車,找到“complier.automake.allow.when.app.running”
注意:
因為我的idea是14版本,有的15版本或者是更高的在compiler 裡面是這樣的:
,然後快捷鍵是Ctrl + Shift +A ,一樣找到complier.automake.allow.when.app.running,點選勾選即可。
第三部: 如果你用的浏覽器和我的一樣,那麼就禁用緩存
按F12(更多工具—->開發者工具),找到network,勾選Disable Cache。
親測有效。
另外,如果是eclipse的話,直接在pom.xml檔案當中添加:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>