java 获取动态代理生成的 Class 文件

一  获取 JDK 动态代理生成的 Class 文件

  1.1  System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");此方式只能在爱main函数中使用

  1.2

    
       FileOutputStream out = null;
            try {
                byte[] classFile = ProxyGenerator.generateProxyClass("$Proxy0", DaoImpl.class.getInterfaces());
                out = new FileOutputStream(filePath[0] + "$Proxy0.class");
                out.write(classFile);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    if (out != null) {
                        out.flush();
                        out.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

二 获取 Cglib 动态代理生成的 Class 文件

System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "e:\class");
原文地址:https://www.cnblogs.com/Tony100/p/12842750.html