参考文章
arthas获取spring bean
写一个工具Util
package com.example.lredisson.util;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
* @author lixi
ognl -c 18b4aac2 '#context=@com.example.lredisson.util.OSSSpringUtil@getContext(),#context.getBean("testModel").getAge()'
*
*/
@Component
public class OSSSpringUtil implements ApplicationContextAware {
private static ApplicationContext context;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
context = applicationContext;
}
public static <T> T getBean(String beanName, Class<T> clazz) {
return context.getBean(beanName, clazz);
}
public static Object getBean(String beanName) {
return context.getBean(beanName);
}
public static ApplicationContext getContext() {
return context;
}
}
结果
sc -d com.example.lredisson.util.OSSSpringUtil
class-info com.example.lredisson.util.OSSSpringUtil
code-source /Users/admin/work/llixi/lredisson/target/classes/
name com.example.lredisson.util.OSSSpringUtil
isInterface false
isAnnotation false
isEnum false
isAnonymousClass false
isArray false
isLocalClass false
isMemberClass false
isPrimitive false
isSynthetic false
simple-name OSSSpringUtil
modifier public
annotation org.springframework.stereotype.Component
interfaces org.springframework.context.ApplicationContextAware
super-class +-java.lang.Object
class-loader +-sun.misc.Launcher$AppClassLoader@18b4aac2
+-sun.misc.Launcher$ExtClassLoader@6aceb1a5
classLoaderHash 18b4aac2
Affect(row-cnt:1) cost in 28 ms.
[arthas@12906]$ ognl -c 18b4aac2 '#context=@com.example.lredisson.util.OSSSpringUtil@getContext(),#context.getBean("testModel").getAge()'
@Integer[20]
arthas验证先生代码版本
直接找到需要判断的class,用jad反编译看看结果最简单了啊。