🍁前言
🍁为什么要使用热部署
🔥关于热部署:
- 重启(Restart)∶自定义开发代码,包含类、页面、配置文件等,加载位置restart类加载器
- 重载(ReLoad) : jar包,加载位置base类加载器
🍁手动启动热部署
🔥导入坐标 - 启动开发者工具
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
🔥修改数据
方便测试是否启用了热部署:
详细代码:点击直接查看
@GetMapping("{id}")
public R getById(@PathVariable Integer id){
System.out.println("host deploy...");
System.out.println("host deploy...");
System.out.println("host deploy...");
return new R(true, bookService.getById(id));
}
🔥build project
🔥测试
🍁自动启动热部署
🍁热部署范围配置
如果想要某些文件或者文件夹不参与热部署的配置需要在application.xml中配置以下信息:
# 设置不参与热部署的文件或文件夹
devtools:
restart:
exclude: static/**,public/**,config/application.yml
🍁禁用热部署
🔥方式一
在application.yml中配置:
# 设置不参与热部署的文件或文件夹
devtools:
restart:
exclude: static/**,public/**,config/application.yml
enabled: false
这种形式关闭热部署,优先级别太低,可能关闭之后,别人又从别的配置文件或者其他地方给打开了(在优先级别高的地方),从而导致热部署在此启动.
🔥方式二
🔥在优先级别高的地方禁用热部署。
- 属性加载优先顺序:
由低到高
- 1 Default properties (specified by setting springApplication.setDefaultproperties )
- 2 GPropertySsource annotations on your @Cconfiguration classes. Please note that such property sources are not added to theEnvironment until the application context is being refreshed.This is too late to configure certain properties such as logging.* and spring.main.* which are read before refresh begins.
- 3 Config data (such as application.properties files)
- 4 A RandomValuePropertySource that has properties only in random.* .
- 5 OS environment variables.
- 6 Java System properties ( system.getProperties() ).
- 7 JNDl attributes from java:comp/env .
- 8 ServletContext init parameters.
- 9 Servletconfig init parameters.
- 10 Properties from spRING_APpLICATION_soN (inline JSON embedded in an environment variable or system property).
- 11 Command line arguments.
- 12 properties attribute on your tests.Available on gSpringRootTest and the test annotations for testing a particular slice ofyour application.
- 13 @TestPropertySource annotations on your tests.
- 14 Devtools global settings properties in the SHN’E .config/spring-boot directory when devtools ,s.ati
🔥application.yml配置文件在优先级为3的地方,可以在优先级为6的地方禁用热部署功能:
package com.jkj;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringbootHotDeployApplication {
public static void main(String[] args) {
System.setProperty("spring.devtools.restart.enabled","false");
SpringApplication.run(SpringbootHotDeployApplication.class);
}
}