Arthas访问bean对象
在使用Arthas中ognl命令时需要指定加载目标类的ClassLoader,所以需要先得到classLoader的hashCode
sc -d cn.seenew.habe.business.payorder.utils.UniPayParamFromDB # 1.通过目标类名获取classLoader的hashCode【31cefde0】,利用这个hashCode访问bean
vmtool -x 3 --action getInstances --className cn.seenew.habe.business.payorder.utils.UniPayParamFromDB --express 'instances[0].uniPayPropVO.getWeChatMsgSrcId()' -c 31cefde0 # 调用静态成员变量的方法
vmtool -x 3 --action getInstances --className cn.seenew.habe.business.payorder.utils.UniPayParamFromDB --express 'instances[0].getMerchantIdByOrgCode('11')' -c 31cefde0 # 访问成员方法
vmtool -x 3 --action getInstances --className cn.seenew.habe.business.payorder.utils.UniPayParamFromDB --express 'instances[0].uniPayHosConfigVOList' -c 31cefde0 # 访问静态字段
vmtool -x 3 --action getInstances --className cn.seenew.habe.business.payorder.utils.UniPayParamFromDB --express 'instances[0].payChannelEntityMapper' -c 31cefde0 # 访问注入的bean
vmtool -x 3 --action getInstances --className cn.seenew.habe.business.payorder.utils.UniPayParamFromDB --express 'instances[0].uniPayHosConfigVOList.get(1)' -c 31cefde0 # 访问静态集合中的元素
注意:在获取classLoader时,由于收到动态代理机制的影响,可能同一个目标类,会返回多个classLoader,且不是每个classLoader都能拿到目标类的对象。此时,可以将返回的classLoader的hashCode全拷出,然后先依次带入这些hashCode,执行
vmtool -x 3 --action getInstances --className cn.seenew.habe.business.payorder.utils.UniPayParamFromDB --express 'instances[0]' -c 31cefde0
看哪个classLoader返回的对象集合不为空,就使用这个hashCode。
学习使我充实,分享给我快乐!

浙公网安备 33010602011771号