当前位置:网站首页>How to use Arthas to view class variable values
How to use Arthas to view class variable values
2022-07-07 09:00:00 【bboyzqh】
Use arthas The core idea of viewing class variable values is : By implementing ApplicationContextAware Interface definition ApplicationUtil class , This class can get ApplicationContext All of Bean example , And then through arthas Of ognl View the property value in the class instance .
Easy to build Spring Boot engineering
1. pom rely on
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>zqh.test</groupId>
<artifactId>SpringBootTest</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.19.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>2. Spring Boot Start class
package com.zqh.main;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author fangchen
* @date 2022-01-08 14:33
*/
@SpringBootApplication(scanBasePackages = {"com.zqh.bean"})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
3. Realization ApplicationContextAware Interface tool class
package com.zqh.bean;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
* @author fangchen
* @date 2022-01-08 14:49
*/
@Component
public class ApplicationUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext args) throws BeansException {
applicationContext = args;
}
public static Object getBean(String beanName) {
return applicationContext.getBean(beanName);
}
}
4. View target class
package com.zqh.bean;
import org.springframework.stereotype.Component;
/**
* @author fangchen
* @date 2022-01-08 14:35
*/
@Component("testBean")
public class TestBean {
private int a = 9;
private String str = "this is bboy zqh!";
}
Use Arthas View class variable values
1. start-up Spring Boot Medium main Method
function Application class , Start success log :
2. Download and launch arthas
# download arthas
curl -O https://arthas.aliyun.com/arthas-boot.jar
# start-up arthas, And find the corresponding process , choice , Here is the first
java -jar arthas-boot.jar
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 71175 com.zqh.main.Application
[2]: 70851 /Users/zhuqiuhui/.flow/resources/player.jar
[3]: 70850 /Users/zhuqiuhui/.flow/resources/kafka.jar
[4]: 70852 /Users/zhuqiuhui/.flow/resources/webapp.jar
[5]: 71174 org.jetbrains.jps.cmdline.Launcher
[6]: 36375
[7]: 68267 /Users/zhuqiuhui/.flow/resources/kafka.jar
[8]: 70861 org.jetbrains.idea.maven.server.RemoteMavenServer
[9]: 70732
3. Use arthas View class variable values
[[email protected]]$ ognl '@[email protected]("testBean").a'
@Integer[9]
[[email protected]]$ ognl '@[email protected]("testBean").str'
@String[this is bboy zqh!]Welcome to WeChat official account. : Fang Chen's blog

边栏推荐
- 串口实验——简单数据收发
- 测试人一定要会的技能:selenium的三种等待方式解读,清晰明了
- Three updates to build applications for different types of devices | 2022 i/o key review
- Calf problem
- 阿里p8推荐,测试覆盖率工具—Jacoco,实用性极佳
- 年薪50w阿里P8亲自下场,教你如何从测试进阶
- Un salaire annuel de 50 W Ali P8 vous montrera comment passer du test
- Newly found yii2 excel processing plug-in
- 数字三角形模型 AcWing 1027. 方格取数
- [istio introduction, architecture, components]
猜你喜欢

平台化,强链补链的一个支点

Esp32-ulp coprocessor low power mode RTC GPIO interrupt wake up

Output a spiral matrix C language

Digital triangle model acwing 1027 Grid access

NCS Chengdu Xindian interview experience

【istio简介、架构、组件】

Greenplum 6.x reinitialization

Oracle makes it clear at one time that a field with multiple separators will be split into multiple rows, and then multiple rows and columns. Multiple separators will be split into multiple rows, and

Three updates to build applications for different types of devices | 2022 i/o key review

Pointer advanced, string function
随机推荐
【Istio Network CRD VirtualService、Envoyfilter】
Pointer advanced, string function
面板显示技术:LCD与OLED
【ChaosBlade:根据标签删除POD、Pod 域名访问异常场景、Pod 文件系统 I/O 故障场景】
STM32的时钟系统
串口实验——简单数据收发
STM32串口寄存器库函数配置方法
硬件大熊原创合集(2022/05更新)
阿里p8推荐,测试覆盖率工具—Jacoco,实用性极佳
Analysis of Hessian serialization principle
OpenGL三维图形绘制
channel. Detailed explanation of queuedeclare parameters
Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
[istio introduction, architecture, components]
Reading notes of pyramid principle
年薪50w阿里P8亲自下场,教你如何从测试进阶
Introduction to data fragmentation
Simulation volume leetcode [general] 1706 Where does the ball meet
Oracle makes it clear at one time that a field with multiple separators will be split into multiple rows, and then multiple rows and columns. Multiple separators will be split into multiple rows, and
Simulation volume leetcode [general] 1609 Parity tree