本文
from :
這裏
後端開發中熱部署有很多方式,但是在開發 SpringBoot 項目有一種 Spring Boot 給我們提供好的很方便的一種方式,配置起來也很簡單。
熱部署可以簡單的這樣理解:我們修改程序代碼後不需要重新啓動程序,就可以獲取到最新的代碼,更新程序對外的行爲。
熱部署在我們日常開發可以爲我們節省很多時間,通常我們在開發後端的過程中,當我們修改了後端代碼之後都需要重啓一下項目,這爲我們浪費了時間,特別是在項目比較龐大,需要耗費大量時間的啓動的時候。這種方式好像消耗性能挺大的,也需要慎重使用。
下面介紹一下如何通過 SpringBoot 提供的 spring-boot-devtools 實現簡單的熱部署。
依賴:
Maven:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
Gradle:
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools")
}
添加配置:
ctrl+,(Win) / cmd+(Mac)打開項目配置:
輸入 Compiler , 並且勾選上 Build project automatically
輸入快捷鍵 ctrl + shift + alt + / (Win)cmd+option+shift+/(Mac),並且選擇 Registry
然後勾選上 Compiler autoMake allow when app running
很簡單,這樣你每次修改程序之後就不用重新啓動了。