关于spring-boot-devtools热启动

准备: springboot+maven项目

ide:eclipse

原因:开发用的IDE 是 eclipse, 由于本人习惯边写代码边调试,所以配置了 spring-boot-devtools,然后嘞,由于习惯性按 ctrl+s 保存(毕竟对程序员来说随手保存代码这个事情很重要),然而, 这个重启服务的检查方式是编译之后的 class 文件是否发生变化,这个是正常的,但是呢, eclipse 保存完代码就会触发 class 的更新,导致按一次 ctrl+s(代码修改的前提), 服务重启一次,这样就很头疼了,于是乎简单的了解了一下有关这方面的一点点知识,随手记个笔记.

引用 spring-boot 官方文档(1.5.4.RELEASE)

"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 will cause the classpath to be updated and trigger a restart. In IntelliJ IDEA, building the project (Build -> Make Project) will have the same effect."

第一步:需要配置spring.devtools.restart.trigger-file属性

方法一:java 代码添加:

//trigger是我在 application.properties所在的目录添加的一个空白文件
//必须得在 run方法前边
System.setProperty("spring.devtools.restart.trigger-file", "trigger");
SpringApplication.run(SpringbootdemoApplication.class, args);

方法二: application.properties

spring.devtools.restart.trigger-file=trigger #trigger是我在 application.properties所在的目录添加的一个空白文件

第二步:其实这时候已经是配置完成了

在完成代码需要重启服务的时候编辑一下 trigger 文件即可触发重启,如果 java 代码没有更新,只更新 trigger是不会触发服务重启的.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值