Springboot開發中使用熱載入
阿新 • • 發佈:2022-04-11
熱部署和熱載入區別:
1、熱部署
專案已經執行,某個模組變更之後,無需重啟tomcat,但是會清空記憶體,重新打包,重新解壓war包執行。
2、熱載入
監聽專案檔案變化,包括web-inf/class,wen-inf/lib,web-inf/web.xml等檔案,若發生更改,則區域性進行載入,不清空session ,不釋放記憶體。開發中用的多,但是要考慮記憶體溢位的情況。
那麼基於idea開發springboot專案如何使用熱載入?
1、整合spring-boot-devtools包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <version>2.6.6</version> </dependency>
2、修改plugins配置
<plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> <!-- 支援熱載入 --> </configuration> </plugin> </plugins>
3、修改application.properties配置
spring.devtools.restart.enabled=true
4、修改idea配置,找到工具欄,File>Settings>Build,Execution,Deployment>Compiler,勾選:Build project automatically,點選【OK】儲存。
這時候你會說......對,沒卵用!!!
還有個地方需要設定,不過要區分下版本,看看你的IDEA版本。
2021.2之前
Ctrl+Shift+Alt+/,召喚Registry,找到並勾選 compiler.automake.allow.when.app.running
2021.2之後
找到Advanced Settings,勾選如下: