[TOC]
arthas有一下幾個(gè)默認(rèn)對(duì)象:
params 參數(shù)
target 當(dāng)前對(duì)象
returnObj 返回值
throwExp 異常
調(diào)用具體時(shí)間
-b(調(diào)用前)、 -e(異常時(shí))颓帝、-s(返回后)米碰、-f(結(jié)束后)
通用參數(shù)
-n 限制打印的條數(shù),如程序執(zhí)行中购城,可能有些方法會(huì)瘋狂打印吕座。
-i 設(shè)置打印間隔時(shí)間,單位毫秒
-x 屬性遍歷深度瘪板,默認(rèn)為1吴趴。
1、tt 命令詳細(xì)使用
過(guò)濾制定參數(shù)
tt -t *UserLoanBiz getOvdRecordCnt 'params[0].toString()=="386134842398343168"'
修改第一個(gè)參數(shù)侮攀,然后調(diào)用實(shí)例的getIContracts方法
tt -i 1101 -w "#a=params[0].setLimit(1),target.getIContracts(#a)"
2锣枝、獲取系統(tǒng)bean
2.1
通過(guò)spring mvc 獲取bean
tt -t org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter invokeHandlerMethod
# 之后通過(guò)如下命令來(lái)獲取具具體bean
tt -i 1000 -w 'target.getApplicationContext().getBean("YourBeanName").fun()'
2.2
自定義類(lèi)獲取Spring ApplicationContent
想辦法拿到項(xiàng)目中 ApplicationContext 對(duì)象。ognl只獲取靜態(tài)屬性兰英,所以我們一般需要查找項(xiàng)目中是否存在靜態(tài)的ApplicationContext對(duì)象惊橱。
這里面我就自己創(chuàng)建了一個(gè)類(lèi)來(lái)提供靜態(tài)的ApplicationContext。
public class BeanFactory implements ApplicationContextAware, DisposableBean {
private static ApplicationContext ctx;
private static BeanFactory singleton = new BeanFactory();
private BeanFactory() {
}
public static BeanFactory getInstance() {
return singleton;
}
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
ctx = applicationContext;
}
public void destroy() throws Exception {
ctx = null;
}
public static <T> T getBean(String name) {
return ctx.getBean(name);
}
public static <T> T getBean(Class<T> clazz) {
return clazz.cast(BeanFactoryUtils.beanOfTypeIncludingAncestors(ctx, clazz));
}
}
然后通過(guò)如下的命令獲取任務(wù)想要的bean,simpleMockContainer為你想要獲取的bean名稱(chēng)
ognl '@com.xxx.admin.utils.BeanFactory@ctx.getBean("simpleMockContainer")' -x 2
參考
Alibaba Arthas實(shí)踐--獲取到Spring Context箭昵,然后為所欲為
使用Arthas 獲取Spring ApplicationContext還原問(wèn)題現(xiàn)場(chǎng)