使用idea開發軟件實現springboot熱部署:
1、添加依賴,在pom.xml文件中添加依賴
<!--熱部署--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency>
2、啓動自動編譯,打鉤 File/settings/Compiler/Build Project autoMatically
3、選擇Tomcat的 On 'Update' action 和 On frame deactivation 的選項爲 '更新類和資源'
4、ctrl + shift + alt + /,選擇Registry,勾上 Compiler autoMake allow when app running
到此爲止,既已經實現了熱部署,在更該頁面和後臺代碼時,只需刷新頁面即可,不需再重新啓動服務器,
測試
- 修改類–>保存:應用會重啓
- 修改配置文件–>保存:應用會重啓
- 修改頁面–>保存:應用不會重啓,但會重新加載,頁面會刷新(原理是將spring.thymeleaf.cache設爲false,參考:Spring Boot配置模板引擎)