准备: 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是不会触发服务重启的.