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

一、操作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);
	}

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值