什么是热部署
- 应用正在运行的时候升级功能, 不需要重新启动应用
- 对于Java应用程序来说, 热部署就是在运行时更新Java类文件
好处:不需要重新手工启动应用,提高本地开发效率
常见实现热部署的方式
- Jrebel (非springboot)
- Spring Loaded(非springboot)
- spring-boot-devtools(springboot自带的,只需要添加一个依赖)
注意线上一定不要开启热部署(会给黑客有机可乘)
springboot2.x结合dev-tool实现IDEA项目热部署
步骤
- pom文件添加依赖包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork><!--必须添加这个配置-->
</configuration>
</plugin>
</plugins>
</build>
IDEA配置
- idea里面要设置,window和mac一样
使用快捷键打开,选择Registry 注意默认快捷键: window快捷键 Shift+Ctrl+Alt+/ mac快捷键 Shift+Command+Alt+/ 如果自行修改了默认快捷键,则百度搜索相关博文,或者还原快捷键设置
选择compiler.automake.allow.when.app.running ,重启idea就行!!!
注意热部署并不是一定会生效,有时候修改配置文件还是要进行重启操作
下一章介绍springboot2.x中的配置文件