有几篇不错的文章
- https://springframework.guru/spring-boot-developer-tools/
- https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools
As DevTools monitors classpath resources, the only way to trigger a restart is to update the classpath. The way in which you cause the classpath to be updated depends on the IDE that you are using:
-
In Eclipse, saving a modified file causes the classpath to be updated and triggers a restart.
-
In IntelliJ IDEA, building the project (Build +→+ Build Project) has the same effect.
简而言之就是,不同IDE触发重启方式不一样
- Eclipse保存文件既可以触发重启
- IntelliJ IDEA 需要重新构建项目
1、页面热部署 application.properties文件中配置
spring.thymeleaf.cache=false
2、类文件热部署
spring-boot-devtools
1、添加依赖
org.springframework.boot
spring-boot-devtools
true
实际使用发现,不用配置application.yml
也可以实现自动重启
spring:
devtools:
restart:
enabled: true
3、将项目设置为自动加载
1、打开设置 勾选 Build project automatically 2、打开 Maintenance 选择 1.Register
快捷键 (一起按下四个按键)
windows: Ctrl + Shift +Alt + /
Mac : command + shift + option + / 3、勾选 compiler.automake.allow.when.app.running
IDEA过一会就会响应变化重启服务,如果想要快速触发,就重新编译
这里分享一份技巧:
保存文件的快捷键是 command + S
设置自动构建后需要等待一会才进行自动构建,这样明显不能等。 可以设置构建文件的快捷键:control + S,此时可以不设置自动构建,修改文件后手动进行构建。
Live ReloadChrome插件 Live Reload 支持前端页面开发修改文件后自动刷新页面
注意:html、css、js文件同样需要build
到classpath路径下
使用依赖, 无需设置
org.springframework.boot
spring-boot-devtools
runtime
true
java 代码的修改重启服务
二、前端配合Chrome浏览器插件 Live Reload,无需设置
前端代码html、js、css文件的修改浏览器自动刷新
参考 SpringBoot热部署自动重启 spring-boot-devtools