方式一(添加依赖)
1.添加依赖
使用spring-boot-devtools提供的开发者工具
spring-boot项目中引入如下依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
2.设置
1.进入设置(ctrl+alt+s)—Build,Execution,Deployment> Compiler 勾选中左侧的Build Project automatically。
2、IDEA开启项目运行时自动make, ctrl + shift + alt+/ 命令:registry -> 勾选。
这样就可以热部署了,每次保存后可能需要等3秒左右才会自动重新编译。
还有一个设置是compiler.automake.postpone.when.idle.less.than默认是3000毫秒。意思:编译器自动延迟,当空闲小于3000毫秒时。可以设置短一点,这样每次修改后可以尽快的编译。
至此热部署以实现
方式二(热部署插件JRebel)
上面那个方式其实已经实现了热部署。不过每次修改了Java代码保存后会自动重启。
有一个简单且好用的插件也可以实现热部署。就是 JRebel 。它每次只替换修改后的.class文件,热部署速度会快很多。
我是参考别人的博客来使用的。
热部署插件JRebel链接:https://blog.csdn.net/weixin_42831477/article/details/82229436
如果英文还不错,看这里JRebel官方文档:https://manuals.jrebel.com/jrebel/ide/index.html