【Arthas】单元测试使用Arthas输出动态代理增强类
1. 单元测试方法新增代码,阻止程序终止
System.in.read();
2. 启动Arthas
选择项目 com.intellij.rt.junit.JUnitStarter 代表是单元测试进程
3. 查询指定类的增强类
sc *ControllerName*
输出
com.controller.ControllerName
com.controller.ControllerName$$EnhancerBySpringCGLIB$$1
com.controller.ControllerName$$EnhancerBySpringCGLIB$$1$$FastClassBySpringCGLIB$$2
com.controller.ControllerName$$FastClassBySpringCGLIB$$3
4. 代码输出到文件中
jad com.controller.ControllerName > C:\\ControllerName1.java
jad com.controller.ControllerName$$EnhancerBySpringCGLIB$$1 > C:\\ControllerName2.java
jad com.controller.ControllerName$$EnhancerBySpringCGLIB$$1$$FastClassBySpringCGLIB$$2 > C:\\ControllerName3.java
jad com.controller.ControllerName$$FastClassBySpringCGLIB$$3 > C:\\ControllerName4.java
仅输出指定方法的源码
jad com.controller.ControllerName$$EnhancerBySpringCGLIB$$1 methodName > C:\\ControllerNameMethod.java
jad --help
jad --source-only
5. 增强类源码
CGLib方式增强,使用拦截器(MethodInterceptor)执行AOP相关代码
com.controller.ControllerName$$EnhancerBySpringCGLIB$$1
public class ControllerName$$EnhancerBySpringCGLIB$$1
extends ControllerName
implements SpringProxy,
Advised,
Factory {
public final Result TestMethod(String string) {
try {
MethodInterceptor methodInterceptor = this.CGLIB$CALLBACK_0;
if (methodInterceptor == null) {
ControllerName$$EnhancerBySpringCGLIB$$1.CGLIB$BIND_CALLBACKS(this);
methodInterceptor = this.CGLIB$CALLBACK_0;
}
if (methodInterceptor != null) {
return (Result)methodInterceptor.intercept(this, CGLIB$TestMethod$0$Method, new Object[]{string}, CGLIB$TestMethod$0$Proxy);
}
return super.TestMethod(string);
}
catch (Error | RuntimeException throwable) {
throw throwable;
}
catch (Throwable throwable) {
throw new UndeclaredThrowableException(throwable);
}
}
分类:
调试
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
2016-02-25 Java_导出Excel
2014-02-25 为什么数据可以从pl/sql查出来而使用ado.net查询,结果却是空?