<!--热部署坐标--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional></dependency>
spring:devtools:restart:enabled:trueadditional-paths: src/main/java
对应的快捷键:Ctrl + F9
上述过程每次进行热部署都需要开发者手工操作,不管是点击按钮,还是快捷键都需要手工操作。如果能让程序自己执行热部署,就可以减少开发者操作,也就是自动进行热部署。详细步骤,看以下内容。
<!--热部署坐标--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional></dependency>
spring:devtools:restart:enabled:trueadditional-paths: src/main/java
(1)File --> Settings… --> Build、Execution、Deployment -->Compile --> 勾选Build project automatically --> Apply --> OK
(2)File --> Settings… --> Advanced Settings --> 勾选Allow auto make to start even if developed application is currently running --> Apply --> OK
(3)同时按住 Ctrl + Alt + Shift + / ,出现弹窗,选择Registry…
(4)搜索:compiler.automake.postpone.when.idle.less.than,根据自己的需求修改value值(毫秒)
<!--热部署坐标--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional></dependency>
spring:devtools:restart:enabled:trueadditional-paths: src/main/java
(1)File --> Settings… --> Build、Execution、Deployment -->Compile --> 勾选Build project automatically --> Apply --> OK
(2)同时按住 Ctrl + Alt + Shift + / ,出现弹窗,选择Registry…
(3)搜索:compiler.automake.allow.when.app.running,并勾选
通过修改项目中的文件,可以发现并不是所有的文件修改都会激活热部署。原因在于在开发者工具中有一组配置,当满足了配置中的条件后,才会启动热部署,配置中默认不参与热部署的目录信息如下:
spring:devtools:restart:# 设置不参与热部署的文件或文件夹exclude: static/**,public/**,resources/**
热部署功能是一个典型的开发阶段使用的功能,到了线上环境运行程序时,这个功能就没有意义了。能否关闭热部署功能呢?
答案是肯定的。线上环境运行时是不可能使用热部署功能的,所以需要强制关闭此功能,通过配置可以关闭此功能。
spring:devtools:restart:enabled:false
如果当心配置文件层级过多导致相符覆盖最终引起配置失效,可以提高配置的层级,在更高层级中配置关闭热部署。例如在启动容器前通过系统属性设置关闭热部署功能。
@SpringBootApplicationpublicclassSpringboot10DevtoolsApplication{publicstaticvoidmain(String[] args){//关闭热部署System.setProperty("spring.devtools.restart.enabled","false");SpringApplication.run(Springboot10DevtoolsApplication.class, args);}}
提示:请勿发布广告垃圾评论,否则封号处理!!