SpringBoot 从入门到光头 —— 第十七章 SpringBoot 与热部署
在开发中我们修改一个 Java 文件后想看到效果不得不重启应用,这导致大量时间花费,我们希望不重启应用的情况下,程序可以自动部署(热部署)。有以下四种情況,如何能实现热部署。
模板引擎
- 在 SpringBoot 中开发情况下禁用模板引擎的 Cache
- 页面模板按下 ⌘F9(Windows 系统下则为:CtrlF9)可以重新编译当前页面并生效
SpringLoaded:Spring 官方提供的热部署程序,实现修改类文件的热部署
- 下载 SpringLoaded:https://github.com/spring-projects/spring-loaded
- 添加运行时参数:
-javaagent:/users/yourname/springloaded-1.3.0.RELEASE.jar -noverify
JRebel
- 一个收费的热部署插件
- 在 IDEA / Eclipse 中安装插件使用即可
SpringBootDevTools(官方推荐)
引入依赖:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency>
在 IDEA 中按下 ⌘F9(Windows 系统下则为:CtrlF9)
或者做一些小调整
IDEA 和 Eclipse 有些不同,Eclipse 设置了自动编译后,修改类之后它会自动编译,而 IDEA 在非 RUN 或 DEBUG 情况下才会自动编译(前提是你已经设置了
Auto-Compile
)- 设置自动编译(
Settings
→Compiler
→Make Project Automatically
) - 按下 ⌘⇧⌥/(Windows 系统下则为:CtrlShiftAltF9)
- 勾选
compiler.automake.allow.when.app.running
- 设置自动编译(