

Java agent 入门遇到点问题
source link: https://www.v2ex.com/t/943064
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

有一个普通的 springboot 项目,我想对项目中的方法执行时间进行计算。然后用 maven 搭了个 agent ,但是使用 java -javaagent 把探针加进去的时候,提示在探针中找不到对应的类。探针的代码,很简单,就是这样的:
ClassPool classPool = new ClassPool(true);
classPool.insertClassPath(new LoaderClassPath(LoadTimeAgent.class.getClassLoader()));
String targentClassName = "com.example.utils.BitStringUtil";
//根据类名获取到要修改的 class
CtClass targetClass = classPool.get(targentClassName);
......下面的代码省略了......
想想确实,agent 里面没有 com.example.utils.BitStringUtil 这样的类,然后我查了资料,说是 springboot 项目,java -javaagent:agent.jar -jar app.jar 的时候,探针中的 class 文件是被 AppClassLoader 加载的,而 springboot 中的 class 文件是被 LunchedURLClassLoader 加载的,而 LunchedURLClassLoader 是 AppClassLoader 的子类,子类( LunchedURLClassLoader )是无法被父类( AppClassLoader )看到的,所以在探针中是无法获取到 springboot 中的类的,那么有没有什么方法能处理?我想,别的探针项目,比如 sw 也不至于获取不到吧?
Recommend
-
81
问与答 - @mfmelsia -
-
106
README.md
-
38
这篇文章是 Danno Ferrin 和我在 DevconV (第六届以太坊开发者大会)上的谈话的粗略记录。文章中讨论了社区在过去一年中提出的一些 EIP 流程改进建议,并且将其纳入到一个统一的框架中用来指导我们如何让以太坊更顺利地升级。我们把它称...
-
10
Java Agent 从入门到内存马 <font color="red">注意:这里只是简短的介绍一下,想要详细了解,请看参考资料。</font> 在JDK1.5以后,javaagent是一种能够在不影响正常编译的情况下,修改字节码。 java作为一...
-
9
华农兄弟:兄弟遇到点小麻烦,帮他解决了,他很开心哦_哔哩哔哩_bilibili活动作品华农兄弟:兄弟遇到点小麻烦,帮他解决了,他很开心哦246.5万播放 · 6.4万弹幕2021...
-
4
大家好,我是张晋涛。本篇我来为你介绍一个我个人很喜欢的,通用策略引擎,名叫 OPA,全称是 Open Policy Agent。在具体聊 OPA 之前,我们先来聊一下为什么需要一个通用策略引擎,以及 OPA 解决了什么问题。OPA 解决了什么问题在...
-
8
← 鸟类大脑的启示 生物的脑子越大,智能程度就越高?majer @ 2022.08.08 , 20:58...
-
6
微信怎么设置到点自动发信息 微信推广 发布日...
-
6
91che 极越点到点领航辅助PPA 再开三城 U型方向盘正式上线 到店皆可体验 电科技辛雯12-28 15:34 144 12月28日,极越...
-
8
V2EX › 宽带症候群 关于点到点专线的问题
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK