# 配置热部署
场景: 在springboot+thymeleaf里面,每次修改了html页面,都得重新启动项目才生效,如何解决呢?
# 对策
启用模板引擎的热更新功能
- 在
pom.xml
中加入以下依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
# 配置注意事项
spring-boot-devtools
适用于开发环境,生产环境中会自动禁用。如果使用 IDE,如 IntelliJ IDEA,确保启用了自动编译:
- Windows/Linux:
Ctrl + Alt + S
>Build, Execution, Deployment
>Compiler
> 勾选 Build project automatically。
- Windows/Linux:
同时,启用 IDEA 的
热更新功能
- 按
Ctrl + Shift + A
(Mac 使用Cmd + Shift + A
),搜索 Registry。 - 搜索并勾选
compiler.automake.allow.when.app.running
。
- 按
效果:保存 HTML 文件后,页面会自动刷新并加载最新的内容。每次修改完按ctrl
+F9
,亦可快速加载最新内容