Spring boot 热部署神器 - JRebel
本文作者:水坎92
下载 JRebel
下载地址: https://www.jrebel.com/products/jrebel/download
如图勾选,下载 JRebel Standalone
破解
解压 jrebel-2020.1.1-nosetup.zip 到 D盘根目录,路径短方便使用
进入 D:\jrebel\bin 目录,双击打开 activate-gui.cmd
GUID 获取:https://www.guidgen.com
服务器地址: https://jrebel.qekang.com/{GUID}
复制GUID,替换服务器地址{GUID},粘贴到 Activate JRebel Team URL 输入框,下面输入框随便写个邮件地址,并勾上 I agree with the terms ......
我用的破解过,就是Change license,点击激活 or 变更。
激活成功
热部署 Spring boot 项目
编写一个Controller进行测试
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
public class JrebelHotDeployController {
@GetMapping("/test")
public String test() {
String desc = "Test Jrebel Hot Deploy.";
log.info(desc);
return desc;
}
}
项目 src/main/resources目录下,加个rebel.xml监控文件,内容:
<?xml version="1.0" encoding="UTF-8"?>
<application generated-by="eclipse"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.zeroturnaround.com"
xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd">
<classpath>
<dir name="D:/eclipse-workspace/school/book-web/target/classes">
</dir>
</classpath>
</application>
替换rebel.xml中name属性成你的项目classes路径,然后使用如下的命令运行项目
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-agentpath:D:\jrebel\lib\jrebel64.dll"
访问 Controller
加个hotMethod
方法,改下 test 方法内容,保存并确保重新编译了,可到classes目录下查看class文件最后修改时间。
package com.lab.book.web.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
public class JrebelHotDeployController {
private String hotMethod() {
return "hotMethod";
}
@GetMapping("/test")
public String test() {
String desc = "Test Jrebel Hot Deploy.--->" + hotMethod();
log.info(desc);
return desc;
}
}
然后控制台会显示类被重新加载了
2020-03-13 17:25:40 JRebel: Reloading class 'com.lab.book.web.controller.JrebelHotDeployController'.
重新访问Controller,test方法,http://localhost:8080/test
内容为:Test Jrebel Hot Deploy.--->hotMethod 这就说明新增方法,修改方法内容都热加载生效了。
标题:Spring boot 热部署神器 - JRebel
作者:shuikan95
地址:http://javadaily.cn/articles/2020/03/13/1584091946452.html
