java 使用javassist 动态修改注解的值
来源:互联网 发布:js页面获取当前时间 编辑:程序博客网 时间:2024/05/17 09:03
如下实例:
@Testpublic void aetTestCaseAtrributes() throws NotFoundException {ClassPool pool = ClassPool.getDefault();// 获取需要修改的类CtClass ct = pool.get("com.XXX.XXX.XXX.XXXX");// 获取类里的所有方法CtMethod[] cms = ct.getDeclaredMethods();for (CtMethod cm : cms) {System.out.println("方法名称====" + cm.getName());MethodInfo methodInfo = cm.getMethodInfo();AnnotationsAttribute attribute = (AnnotationsAttribute) methodInfo.getAttribute(AnnotationsAttribute.visibleTag);System.out.println(attribute);ConstPool cPool = methodInfo.getConstPool();AnnotationsAttribute attribute2 = new AnnotationsAttribute(cPool, AnnotationsAttribute.visibleTag);Annotation[] anns= attribute2.getAnnotations();for(Annotation ann:anns){System.out.println(ann.getTypeName());}Annotation annotation = new Annotation("org.testng.annotations.Test", cPool);annotation.addMemberValue("invocationCount", new LongMemberValue(10L, cPool));attribute2.setAnnotation(annotation);methodInfo.addAttribute(attribute2);Annotation annotation2 = attribute2.getAnnotation("org.testng.annotations.Test");long text = ((LongMemberValue) annotation2.getMemberValue("invocationCount")).getValue();attribute = (AnnotationsAttribute) methodInfo.getAttribute(AnnotationsAttribute.visibleTag);System.out.println(attribute);System.out.println(text);}
0 0
- java 使用javassist 动态修改注解的值
- JAVAssist---动态修改注解
- JAVAssist---动态修改注解
- Java 使用动态代理来动态修改注解值
- 如何在SpringMVC框架中利用Java反射机制和Javassist实现Java对象、属性、注解的动态创建生成
- Android中使用Java开源库Javassist动态创建字节码的学习研究
- java javassist使用实例
- 使用javassist修改class文件
- 使用javassist动态注入代码
- 使用javassist动态注入代码
- 使用javassist动态注入代码
- 使用javassist动态注入代码
- 使用javassist动态注入代码
- 使用javassist动态注入代码
- 使用javassist动态注入代码
- 使用javassist动态注入代码
- 使用javassist动态注入代码
- 使用javassist动态注入代码
- filter过滤器利用HttpServletResponseWrapper操作Response对象
- 数据结构实验之排序五:归并求逆序数
- 页面主体高度不固定,如何让页面的footer始终在最底部
- eclipse创建maven
- 16、SQL Server: if else和case
- java 使用javassist 动态修改注解的值
- 实践干货!猿题库 iOS 客户端架构设计
- HDU5992Finding Hotels 【K-D tree】
- 从汇编角度来解析c程序的运行过程
- Android M运行时权限
- post的两种方式区别:form-data和x-www-form-urlencoded
- mybatis实战教程(mybatis in action),mybatis入门到精通
- 二叉排序树(建树)
- opencv学习_8 ( 图像细化)