IDEA Spring boot devtools 實現熱部署
阿新 • • 發佈:2019-02-14
熱部署的方法有四種,我這採用devtools 這個工具來。
一、開啟idea自動make功能
1、ctrl+shift+a--> 查詢 make project automatically --> 選中
2、ctrl+shift+a --> 查詢 Registry --> 找到並勾選 compiler.automake.allow.when.app.running
重啟idea 重啟idea 重啟idea 重啟idea 重啟idea 重啟idea
二、使用spring-boot-1.3開始有的熱部署功能
1、加maven依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
2、開啟熱部署
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!-- 如果沒有該項配置,devtools不會起作用,即應用不會restart --> <fork>true</fork> </configuration> </plugin> </plugins> </build>
三、Chrome禁用快取
F12(或Ctrl+Shift+J或Ctrl+Shift+I)--> NetWork --> Disable Cache(while DevTools is open)
注意:
1、如果設定SpringApplication.setRegisterShutdownHook(false),則自動重啟將不起作用。
2、這種熱載入比較全面,資原始檔、程式碼的修改都可以監聽到,但有些情況下也會有問題