You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在IntelliJ 2021.2启用Spring Boot Live Dev Tools实现自动重编译部署

IntelliJ IDEA 2021.2 启用Spring Boot DevTools热部署配置教程

配置完成后无需手动重启Tomcat服务器即可实现代码、配置文件、静态资源修改后的实时生效。


步骤1:项目引入Spring Boot DevTools依赖

Maven项目(pom.xml)

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
</dependency>

Gradle项目(build.gradle)

developmentOnly 'org.springframework.boot:spring-boot-devtools'

步骤2:开启IDEA全局自动编译配置

  • 打开IDEA顶部菜单 File -> Settings -> Build,Execution,Deployment -> Compiler
  • 勾选右侧面板的 Build project automatically 选项,点击Apply保存

步骤3:开启运行时自动构建权限

  • 按下快捷键 Ctrl+Shift+A(Mac系统为 Command+Shift+A)调出全局搜索框
  • 输入 Registry 并点击对应结果进入注册表配置页
  • 找到 compiler.automake.allow.when.app.running 选项,勾选后保存

步骤4:调整Spring Boot启动配置

  • 打开IDEA顶部菜单 Run -> Edit Configurations
  • 找到你需要启用热部署的Spring Boot启动项
  • 找到 On 'Update' action 选项,下拉选择 Update classes and resources
  • 找到 On frame deactivation 选项,下拉选择 Update classes and resources
  • 点击Apply保存配置

步骤5:项目配置文件添加DevTools相关配置

在application.properties(或application.yml)中添加如下配置:

# 开启DevTools热部署能力
spring.devtools.restart.enabled=true
# 指定需要监听变更的代码目录
spring.devtools.restart.additional-paths=src/main/java
# 关闭模板引擎缓存(实现前端页面修改实时生效)
spring.thymeleaf.cache=false
# 可选配置:指定不需要触发重启的静态资源目录
# spring.devtools.restart.exclude=static/**,templates/**

注意:如果修改代码后没有自动触发部署,可手动按下 Ctrl+F9 触发项目编译,即可触发变更同步

内容的提问来源于stack exchange,提问作者Pawan.Java

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 03:45:02