实现 Java 热部署的几种解决方案

  • 2020 年 2 月 13 日
  • 筆記

百度百科:热部署,就是应用正在运行的时候就可以升级软件,而不需要重新启动应用。

spring-loaded

  • 依赖
 <dependency>          <groupId>org.springframework</groupId>          <artifactId>springloaded</artifactId>          <version>1.2.5.RELEASE</version>     </dependency>   

ps:据说此方法还需要手动编译(Ctrl + Shift + F9),请亲测!

spring-boot-devtools

  • 依赖
  <dependency>           <groupId>org.springframework.boot</groupId>           <artifactId>spring-boot-devtools</artifactId>           <optional>true</optional><!-- 表示依赖不会传递,之后依赖该module的项目如需继续使用,则需要再次引入 -->       </dependency>   

JRebel

  • 安装插件
  • 激活JRebel
  • 启动运行
  • 若不起效
  • 全局配置

对比

方式

效果

spring-loaded

需手动编译

spring-boot-devtools

会重新加载整个应用

JRebel

只加载修改类(当有错误时不会)。无需手动编译,不会重新加载整个应用

参考文章

SpringBoot初始教程之热部署(五) JRebel无限制版 IntelliJ IDEA 热部署插件 JRebel 安装激活及使用 intellij idea 热部署 jrebel 详细配置

文章已授权转载,原文链接:实现 Java 热部署的几种解决方案