springboot 在idea中实现热部署

修改时间: 2018-11-22 10:46:00 AM

文章时间:2018年11月22日
更新于:2021年1月7日 16:17:03
解决问题:IDEA 项目热部署

添加maven依赖

  • pom中加入devtools
<!-- 热部署 -->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-devtools</artifactId>
  <optional>true</optional>
</dependency>

IDEA配置修改

Settings -> Build,Execution,Deployment -> Compiler -> 勾选 Build project automatically

ctrl + Alt + shift + /

Registry... -> 勾选 compiler.automake.allow.when.app.running

ps:DevTools会监听classpath下的文件变动,并且会在保存文件时立即重启应用。因为采用的是虚拟机机制,所以重启很快。其实类加载器有base classloaderrestart classloader,前者加载不改变的class,例如第三方的jar包,后者主要加载正在开发的class。之所以重启很快,是因为重启的时候只是加载了在开发的class,没有重新加载第三方的jar包


添加新评论