后台管理系统(四)之使用热部署
在开发项目过程中,当修改了某些代码后需要本地验证时,需要重启本地服务进行验证,启动这个
项目,如果项目庞大的话还是需要较长时间的, spring 开发团队为我们带来了一个插件: spring-boot devtools ,很好的解决了本地验证缓慢的问题。
选择 Build 下的 Compiler 选项,在右侧勾选 “Build project automatically” 选项将项目设置为自动编
译,单击【 Apply 】 → 【 OK 】按钮保存设置
在项目任意页面中使用组合快捷键 “Ctrl+Shift+Alt+/” 打开 Maintenance 选项框,选中并打开
Registry 页面,具体如图所示
列表中找到 “compiler.automake.allow.when.app.running” ,将该选项后的 Value 值勾选,用于指
定 IDEA 工具在程序运行过程中自动编译,最后单击【 Close 】按钮完成设置
添加spring-boot-devtools热部署依赖启动器
在 Spring Boot 项目进行热部署测试之前,需要先在项目的 pom.xml 文件中添加 spring-boot-devtools 热部署依赖启动器
由于使用的是 IDEA 开发工具,添加热部署依赖后可能没有任何效果,接下来还需要针对 IDEA 开发 工具进行热部署相关的功能设置 yml配置生效org.springframework.boot spring-boot-devtools true org.springframework.boot spring-boot-maven-plugin true
# devtools debug: true spring: devtools: restart: enabled: true #设置开启热部署 freemarker: cache: false #页面不加载缓存,修改即时生效
IDEA工具热部署设置
选择 IDEA 工具界面的【 File 】 -> 【 Settings 】选项,打开 Compiler 面板设置页面

此选项在IntelliJ IDEA 2021.2之后的版本迁移到高级设置中。如下图所示:
如果你安装了中文语言包,那么它在这里
热部署时间可以配置,配置地址如下: