IDEA環境下使用devtools
實現熱加載與熱部署實現修改代碼不需重啟
1.引入devtools的maven依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
2.在 plugin 中配置另外一個屬性 fork,並且配置為 true。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
3.設置IDEA
運行時編譯配置:組合鍵:“Shift+Ctrl+Alt+/” ,選擇 “Registry” ,選中打勾 “compiler.automake.allow.when.app.running” 。
4.自動化編譯配置:
“File” -> “Settings” -> “Build,Execution,Deplyment” -> “Compiler”,選中打勾 “Build project automatically” 。
5. 進行一下application.properties配置
在有些版本我們需要配置熱加載生效的開關,使其值等於true。下文是properties格式配置,喜歡yml格式的同學可以自行調整一下
#熱加載生效
spring.devtools.restart.enabled=true
#額外新增的熱加載目錄
spring.devtools.restart.additional-paths= src/main/java
#熱加載排除目錄
#spring.devtools.restart.exclude=