当前位置: 首页 > news >正文

使用arthas中vmtool命令查看spring容器中对象的某个属性

场景:

线上环境我想查看spring中容器某个对象的属性值

vmtool命令

方式一:

 vmtool --action getInstances -c   [类加载器的hash]    --className  [目标类全路径]  --limit 10 -x 2

 实例:查询该类的全部属性情况(该类是一个spring中容器的对象,因此可以直接可以看到线上运行的属性值情况

 vmtool --action getInstances -c 7637f22   --className com.gisquest.cloud.oauth2.authentication.GisqAuthenticationSuccessHandler  --limit 10 -x 2

方式二:

语法:

 vmtool --action getInstances    -c [类加载器的hash] --className [org.springframework.web.context.WebApplicationContext]--express 'instances[0].getBean("对象名")' 

实例:查询spring容器中的某个对象

 vmtool --action getInstances    -c [ 7637f22] --className [org.springframework.web.context.WebApplicationContext]--express 'instances[0].getBean("gisqAuthenticationSuccessHandler")' 

语法:

 vmtool --action getInstances -c 7637f22   --className 【容器全路径】--express 'instances[0].getBean("实例对象名").【属性名】' 

实例:查询spring容器中的某个对象的某个属性值

 vmtool --action getInstances -c 7637f22   --className org.springframework.web.context.WebApplicationContext --express 'instances[0].getBean("gisqAuthenticationSuccessHandler").needUpdatePwdTime' 

可能遇到的问题 :

问题一:参照官网直接复制 org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named

  vmtool --action getInstances  --className org.springframework.context.ApplicationContext --express 'instances[0].getBean("gisqAuthenticationSuccessHandler")' 
Failed to execute ognl, exception message: ognl.MethodFailedException: Method "getBean" failed for object org.springframework.context.annotation.AnnotationConfigApplicationContext@91161c7, started on Tue Feb 07 11:08:21 CST 2023 [org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'gisqAuthenticationSuccessHandler' available], please check $HOME/logs/arthas/arthas.log for more details. 
[arthas@1]$ 

 原因:在实际的项目中往往是web容器,因此容器全类名需要根据实际情况改动。

 vmtool --action getInstances  --className org.springframework.web.context.WebApplicationContext --express 'instances[0].getBean("gisqAuthenticationSuccessHandler")' 

问题二:获取当前类是那个类加载器加载的

sc -d 【目标类】

 实例:

sc -d com.gisquest.cloud.oauth2.authentication.GisqAuthenticationSuccessHandler

http://www.lryc.cn/news/1811.html

相关文章:

  • 四种幂等性解决方案
  • 【Nacos】Nacos配置中心客户端配置更新源码分析
  • 按钮防抖与节流-vue2
  • PyTorch学习笔记:nn.SmoothL1Loss——平滑L1损失
  • 2年时间,涨薪20k,想拿高薪还真不能老老实实的工作...
  • Spark - Spark SQL中RBO, CBO与AQE简单介绍
  • NeurIPS/ICLR/ICML AI三大会国内高校和企业近年中稿量完整统计
  • Android IO 框架 Okio 的实现原理,到底哪里 OK?
  • 一文讲解Linux 设备模型 kobject,kset
  • linux配置密码过期的安全策略(/etc/login.defs的解读)
  • c_character_string 字符串----我认真的弄明白了,也希望你们也是。
  • spring面试题 一
  • C++中char *,char a[ ]的特殊应用
  • 【Windows10】电脑副屏无法调节屏幕亮度?解决方法
  • Paper简读 - ProGen2: Exploring the Boundaries of Protein Language Models
  • leaflet 加载WKT数据(示例代码050)
  • 设计模式-组合模式和建筑者模式详解
  • Pcap文件的magic_number
  • MDS75-16-ASEMI三相整流模块MDS75-16
  • 基本TCP编程
  • 【沁恒WCH CH32V307V-R1开发板读取板载温度实验】
  • 学习SpringCloudAlibaba(二)微服务的拆分与编写
  • 通过对HashMap的源码分析解决部分关于HashMap的问题
  • 【无标题】
  • 渗透测试 -- 网站信息收集
  • Windows 搭建ARM虚拟机 UOS系统
  • day58每日温度_下一个更大元素1
  • 超清遥感影像语义分割处理
  • RabbitMQ安装及配置
  • 网络协议(四):网络互联模型、物理层、数据链路层