zoukankan      html  css  js  c++  java
  • 【Arthas】单元测试使用Arthas输出动态代理增强类

    1. 单元测试方法新增代码,阻止程序终止

    System.in.read();
    

    2. 启动Arthas

    选择项目 com.intellij.rt.junit.JUnitStarter 代表是单元测试进程


    3. 查询指定类的增强类

    sc *ControllerName*
    

    输出

    com.controller.ControllerName
    com.controller.ControllerName$$EnhancerBySpringCGLIB$$1
    com.controller.ControllerName$$EnhancerBySpringCGLIB$$1$$FastClassBySpringCGLIB$$2
    com.controller.ControllerName$$FastClassBySpringCGLIB$$3
    

    4. 代码输出到文件中

    jad com.controller.ControllerName > C:\ControllerName1.java
    jad com.controller.ControllerName$$EnhancerBySpringCGLIB$$1 > C:\ControllerName2.java
    jad com.controller.ControllerName$$EnhancerBySpringCGLIB$$1$$FastClassBySpringCGLIB$$2 > C:\ControllerName3.java
    jad com.controller.ControllerName$$FastClassBySpringCGLIB$$3 > C:\ControllerName4.java
    

    仅输出指定方法的源码

    jad com.controller.ControllerName$$EnhancerBySpringCGLIB$$1 methodName > C:\ControllerNameMethod.java
    
    jad --help
    jad --source-only
    

    5. 增强类源码

    CGLib方式增强,使用拦截器(MethodInterceptor)执行AOP相关代码
    com.controller.ControllerName$$EnhancerBySpringCGLIB$$1
    
    
    public class ControllerName$$EnhancerBySpringCGLIB$$1
    extends ControllerName
    implements SpringProxy,
    Advised,
    Factory {
        
        public final Result TestMethod(String string) {
        try {
            MethodInterceptor methodInterceptor = this.CGLIB$CALLBACK_0;
            if (methodInterceptor == null) {
                ControllerName$$EnhancerBySpringCGLIB$$1.CGLIB$BIND_CALLBACKS(this);
                methodInterceptor = this.CGLIB$CALLBACK_0;
            }
            if (methodInterceptor != null) {
                return (Result)methodInterceptor.intercept(this, CGLIB$TestMethod$0$Method, new Object[]{string}, CGLIB$TestMethod$0$Proxy);
            }
            return super.TestMethod(string);
        }
        catch (Error | RuntimeException throwable) {
            throw throwable;
        }
        catch (Throwable throwable) {
            throw new UndeclaredThrowableException(throwable);
        }
    }
    
  • 相关阅读:
    DB2 字段操作
    解析二维码
    Eclipse tomcat 内存溢出
    hereim_美句_1
    js自定义函数默认参数的写法
    PHP和JS判断访问客户端的是PC还是移动设备
    lampp服务器配置httpd-vhosts.conf文件,设置多域名
    价值7000万的商业模式,羊毛出在狗身上,猪来买单
    确保 PHP 应用程序的安全
    美国淘金的故事
  • 原文地址:https://www.cnblogs.com/gossip/p/14446217.html
Copyright © 2011-2022 走看看