arthas 执行ognl表达式ClassNotFoundException

1 问题描述

不希望通过编码的方式,想通过arthas 获取spring 属性。

参考一篇文章https://my.oschina.net/u/4255537/blog/3357593 根据applicationcontext 工具类获取配置属性的方法。

实际执行时总是报找不到类, 但是通过sc 命令可以找到该类

[arthas@312]$ ognl '#context=@com.xxx.ApplicationContextHelper@appCtx,#context.getEnvironment().getProperty("author")'
Failed to execute ognl, exception message: ognl.OgnlException: Could not get static field appCtx from class com.xxx.ApplicationContextHelper [java.lang.ClassNotFoundException: Unable to resolve class: com.xxx.ApplicationContextHelper], please check $HOME/logs/arthas/arthas.log for more details. 

[arthas@312]$ sc com.xxx.ApplicationContextHelper
com.xxx.ApplicationContextHelper

2 原因分析

搜到了 arthas 对该问题解释,大意是自定义类加载器导致找不到类

https://github.com/alibaba/arthas/issues/71

解决办法:

第一步,查询指定类的classloader信息,命令为:sc -d xxxx,根据结果可以看到类对应classloader的hash值;
第二步,ognl命令指定classloader,命令为:ognl -c xxxx(classloader的hash值) xxx(表达式)

3 解决方案

  1. su app
  2. as.sh
  3. sc -d com.xxx.ApplicationContextHelper
    找到 classLoaderHash 41a2befb
  4. ognl -c 41a2befb ‘#context=@com.xxx.ApplicationContextHelper@appCtx,#context.getEnvironment().getProperty(“druid.datasource.password”)’

4 相关资料

https://github.com/alibaba/arthas/issues/71

https://blog.csdn.net/qq826654664jx/article/details/101512468

https://commons.apache.org/proper/commons-ognl/language-guide.html

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

明明如月学长

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值