当前位置:网站首页>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
边栏推荐
- Greenplum 6.x build_ Environment configuration
- Markdown editor Use of MD plug-in
- Greenplum 6.x reinitialization
- Goldbach conjecture C language
- Why choose cloud native database
- Database storage - table partition
- Personal deduction topic classification record
- C语言指针(中篇)
- LeetCode 715. Range 模块
- Reflections on the way of enterprise IT architecture transformation (Alibaba's China Taiwan strategic thought and architecture practice)
猜你喜欢
External interrupt to realize key experiment
【Istio Network CRD VirtualService、Envoyfilter】
LeetCode 715. Range 模块
Digital triangle model acwing 275 Pass a note
2022-06-30 Unity核心8——模型导入
Output a spiral matrix C language
Goldbach conjecture C language
Screen automatically generates database documents
LeetCode 715. Range module
Recommended by Alibaba P8, the test coverage tool - Jacobo is very practical
随机推荐
With an annual salary of 50W, Alibaba P8 will come out in person to teach you how to advance from testing
如何统计项目代码行数
Find the original code, inverse code and complement of signed numbers [C language]
9c09730c0eea36d495c3ff6efe3708d8
Speaking of a software entrepreneurship project, is there anyone willing to invest?
ncs成都新電面試經驗
Mock. JS usage details
Several common database connection methods
Golang etcdv3 reports an error. The attribute in grpc does not exist
2022-06-30 Unity核心8——模型导入
Common operating commands of Linux
Synchronized underlying principle, volatile keyword analysis
C语言指针(上篇)
External interrupt to realize key experiment
Problems encountered in the use of go micro
How to realize sliding operation component in fast application
2022-07-06 Unity核心9——3D动画
MAC OSX php dyld: Library not loaded: /usr/local/xxxx. dylib
selenium自动化集成,八年测试经验软测工程师,一篇文章带你学懂
Personal deduction topic classification record