[TOC]
arthas有一下幾個默認(rèn)對象:
params 參數(shù)
target 當(dāng)前對象
returnObj 返回值
throwExp 異常
調(diào)用具體時間
-b(調(diào)用前)、 -e(異常時)、-s(返回后)、-f(結(jié)束后)
通用參數(shù)
-n 限制打印的條數(shù),如程序執(zhí)行中,可能有些方法會瘋狂打印。
-i 設(shè)置打印間隔時間,單位毫秒
-x 屬性遍歷深度,默認(rèn)為1。
1、tt 命令詳細(xì)使用
過濾制定參數(shù)
tt -t *UserLoanBiz getOvdRecordCnt 'params[0].toString()=="386134842398343168"'
修改第一個參數(shù),然后調(diào)用實(shí)例的getIContracts方法
tt -i 1101 -w "#a=params[0].setLimit(1),target.getIContracts(#a)"
2、獲取系統(tǒng)bean
2.1
通過spring mvc 獲取bean
tt -t org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter invokeHandlerMethod
# 之后通過如下命令來獲取具具體bean
tt -i 1000 -w 'target.getApplicationContext().getBean("YourBeanName").fun()'
2.2
自定義類獲取Spring ApplicationContent
想辦法拿到項(xiàng)目中 ApplicationContext 對象。ognl只獲取靜態(tài)屬性,所以我們一般需要查找項(xiàng)目中是否存在靜態(tài)的ApplicationContext對象。
這里面我就自己創(chuàng)建了一個類來提供靜態(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));
}
}
然后通過如下的命令獲取任務(wù)想要的bean,simpleMockContainer為你想要獲取的bean名稱
ognl '@com.xxx.admin.utils.BeanFactory@ctx.getBean("simpleMockContainer")' -x 2