您当前的位置: 首页 >  spring

彭世瑜

暂无认证

  • 6浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

SpringBoot开发模式自动重启热部署spring-boot-devtools

彭世瑜 发布时间:2020-07-04 12:15:09 ,浏览量:6

有几篇不错的文章

  • https://springframework.guru/spring-boot-developer-tools/
  • https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools
Triggering a restart

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也可以实现自动重启

2、修改配置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 Reload

Chrome插件 Live Reload 支持前端页面开发修改文件后自动刷新页面

注意:html、css、js文件同样需要build 到classpath路径下

总结:Spring Boot Live Reload 一、后端

使用依赖, 无需设置


    org.springframework.boot
    spring-boot-devtools
    runtime
    
    true

java 代码的修改重启服务

二、前端

配合Chrome浏览器插件 Live Reload,无需设置

前端代码html、js、css文件的修改浏览器自动刷新

参考 SpringBoot热部署自动重启 spring-boot-devtools

关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.1816s