学无先后,达者为师

网站首页 编程语言 正文

arthas操作spring被代理目标对象命令速查

作者:大鱼天 更新时间: 2024-07-15 编程语言

一、操作spring bean对象方法

首先,通过sc命令获取bean类的类加载器hash值,命令如下:

sc -d com.xxx.xxx.web.controller.IndexController

会得到,classLoaderHash   69c112b6,然后执行获取到的spring被代理的目标对象的方法

ognl -x 3 '#springContext=@com.xxx.xxx.service.util.BeanUtil@applicationContext,#springContext.getBean("indexController").health()' -c 69c112b6

如果没有beanUtils工具类,还可以通过vmtool命令

vmtool -x 3 --action getInstances --className com.xxx.xxx.web.controller.IndexController --express 'instances[0].health()' -c 69c112b6

二、操作方法重新消费消息

1.通过ognl重新消费消息

 获取类加载器hash值,同上

ognl -x 3 '#springContext=@com.xxx.xxx.service.util.BeanUtil@applicationContext,#springContext.getBean("storeVenderConsumerHandler").onMessage(new com.xxx.xxx.sdk4.kafka.message.KafkaMsgExt("123","{\"id\":107492,\"level\":\"store\",\"type\":\"update\",\"updateType\":\"base\"}"),null)'  -c 69c112b6

2.通过vmtool重新消费消息

 获取类加载器hash值,同上

vmtool -x 3 --action getInstances --className com.xxx.xxx.web.dafka.client.StoreVenderMessageListener --express 'instances[0].onMessage(new com.xxx.xxx.sdk4.kafka.message.KafkaMsgExt("123","{\"id\":107492,\"level\":\"store\",\"type\":\"update\",\"updateType\":\"base\"}"),null)' -c 69c112b6

附:beanUtils工具类

@Component
public class BeanUtil implements ApplicationContextAware {

	private static ApplicationContext applicationContext;

	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		BeanUtil.applicationContext = applicationContext;
	}

	public static <T> T getBean(String beanName, Class<T> requiredType) {
		return applicationContext.getBean(beanName, requiredType);
	}

}

原文链接:https://blog.csdn.net/kfeng632/article/details/126959717

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新