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

一、操作spring bean对象方法

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

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

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

ognl -x 3 '#[email protected]@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 '#[email protected]@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 getBean(String beanName, Class requiredType) {
		return applicationContext.getBean(beanName, requiredType);
	}

}

你可能感兴趣的:(java,spring,java,后端)