当前位置: 首页 > news >正文

【通过Groovy去热修复线上逻辑】1.执行线上数据修复 2.写工具

1.执行groovy // 实际执行的话, 我们是通过vue管理系统提交

http://localhost:8080/groovy/execute?script=import com.example.groovytest.controller.LoginController;  LoginController.num=251222

还有个技巧: 而执行执行的,则是: 写的工具什么的,想直接使用, 无需打jar包。

2.查询 // 可以看到,每次执行完groovy脚本,逻辑就修改了

http://localhost:8080/login/getNum

3.GroovyService

package com.example.groovytest.service;import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyObject;
import org.springframework.stereotype.Service;@Service
public class GroovyService {public void executeGroovyScript(String script) {try{GroovyClassLoader loader = new GroovyClassLoader();Class<?> groovyClass = loader.parseClass(script);GroovyObject groovyObject = (GroovyObject) groovyClass.getDeclaredConstructor().newInstance();groovyObject.invokeMethod("run", null);}catch (Exception e){throw new RuntimeException(e);}}
}

4.LoginController

package com.example.groovytest.controller;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/login")
public class LoginController {public static volatile int num = 111;@RequestMapping("/getNum")public String getNum() {return String.valueOf(num);}
}

5.GroovyController.java

package com.example.groovytest.controller;import com.example.groovytest.service.GroovyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/groovy")
public class GroovyController {@Autowiredprivate GroovyService groovyService;@RequestMapping("/execute")public String execute(String script) {try {groovyService.executeGroovyScript(script);} catch (Exception e) {return "fail:" + e.getMessage();}return "success";}
}

总结:

1.可见Groovy真的是脚本,我们是通过文本的方式当做字符串去提交的代码。

2.线上的话,我们可以选择都有哪些服务器执行这些逻辑修复,从而快速执行Groovy脚本进行修复即可。


http://www.mrgr.cn/news/95469.html

相关文章:

  • STM32__红外避障模块的使用
  • Cursor从小白到专家
  • Jupyter Notebook 常用命令(自用)
  • 动态规划入门详解
  • DeepSeek本地搭建
  • git | 回退版本 并保存当前修改到stash,在进行整合。[git checkout | git stash 等方法 ]
  • C语言【文件操作】详解中(会使用fgetc,fputc,fgets,fputs,fscanf,fprintf,fread,fwrite函数)
  • 【day1】数据结构刷题 链表
  • 通俗易懂搞懂@RequestParam 和 @RequestBody
  • 细说卫星导航:测距定位原理
  • 【算法笔记】图论基础(一):建图、存图、树和图的遍历、拓扑排序、最小生成树
  • TCP | 序列号和确认号 [逐包分析] | seq / ack 详解
  • 介绍一个测试boostrap表格插件的好网站!
  • 自动驾驶系统的车辆动力学建模:自行车模型与汽车模型的对比分析
  • [学习笔记] VM虚拟机安装Ubuntu系统
  • Axure大屏可视化模板:赋能多领域,开启数据展示新篇章
  • [AI速读]混合验证方案:如何高效解决RISC-V向量扩展的验证难题
  • 文献分享: XTR——优化Token级检索的高效多向量模型
  • 【数学建模】最大最小值模型详解
  • 子集和问题---递归搜索