1.关于热部署:
重启(Restart):自定义开发代码,包含类、页面、配置文件等,加载位置restart类加载器
重载(ReLoad):jar包,加载位置base类加载器
热部署仅仅加载当前开发者自定义开发的资源,不加载jar资源
2.启动热部署
首先,想要启动热部署功能,首先我们需要在pom.xml中添加入下的配置。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
在springboot现在的版本中不需要我们手动添加devtools的配置,在我们创建springboot项目的时候就可以勾选该配置即可。
3.设置自动启动热部署
1.在file--> setting--> Build,Execution,Depliyment -->Compiler中勾选Build project automatically
2.接下来就是在以前的版本idea中和新版idea中设置是不同的,在以前的版本中我们需要组合键Ctrl+Shift+Alt+/,选择Registry,然后勾选如图所示。
3.但是在新版的idea中在 Registry中没有该选项,此时我们就需要在在file--> setting--> Advanced Setting 中去勾选Allow auto-make to start even if developed application is curently runing就可以了。
4.热部署范围配置
1.默认不触发 重启的目录列表/META-INF/maven/META-INF/resources/resources/static/public/templates
2.自定义不参与重启排除项
devtools: restart: exclude: pages/**,static/**
5.禁用热部署
设置高优先级属性禁用热部署
package com.stu;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Springboot12HotDeployApplication {
public static void main(String[] args) {
SpringApplication.run(Springboot12HotDeployApplication.class, args);
}
}
修改成如下即可
public static void main(String[] args) {
System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(Springboot12HotDeployApplication.class);
}