arthas 获取springmvc子容器

org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext(): 获取的是spring容器

org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext().getServletContext():获取的是servletContext对象

springmvc子容器存储在servletContext的attribute中,key为:org.springframework.web.servlet.FrameworkServlet.SERVLET_CONTEXT_PREFIX + servlet名称

不确定名称为何可以将所有attribute打印出来(需要-c指明classloader的hash值):

ognl -c 567eb32e '@org.apache.commons.collections.EnumerationUtils@toList(@org.springframework.web.context.ContextLoader@getCurrentWebApplicationContext().getServletContext().getAttributeNames())'

获取springmvc子容器:

ognl -c 567eb32e '@org.springframework.web.context.support.WebApplicationContextUtils@getWebApplicationContext(@org.springframework.web.context.ContextLoader@getCurrentWebApplicationContext().getServletContext(), "org.springframework.web.servlet.FrameworkServlet.CONTEXT.spring")'


上面方法不适用于springboot项目

所有项目适用的方式vmtool

vmtool -x 1 --action getInstances --className com.xxx.service.impl.XXXXServiceImpl -c 5ffd2b27 --limit 3

-x 1 展开层数,查找类实例时,展开1层即可,可以看到实例类名

--limit 3 最多展示多少个,如果不会特别多可以不限制,默认limit 10个

找到对应实例后,使用实例执行方法

vmtool -x 1 --action getInstances --className com.xxx.service.impl.XXXXServiceImpl -c 5ffd2b27 --express 'instances[1].timedCache.clear()'

--express 执行表达式内的值,instances[1]表示使用实例的第几个,是一个数组,第一个下标为0

参考vmtool | arthas 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值