javagossip / dorado

基于Netty4开发的简单、轻量级、高性能的的Http restful api server
Apache License 2.0
75 stars 24 forks source link

两处代码有问题,希望尽快修复 #5

Closed lohcve closed 11 months ago

lohcve commented 4 years ago

打包为springboot jar运行时,发现两处报错,无法运行。

文件1:/src/main/java/ai/houyi/dorado/rest/LocalVariableTableParameterNameResolver.java

修改如下: `try { String className = method.getDeclaringClass().getName(); ClassPathResource classPathResource = new ClassPathResource(className.replace('.', '/') + ".class"); InputStream inputStream = classPathResource.getInputStream(); ClassReader classReader = new ClassReader(inputStream); classReader.accept(new ClassVisitor(Opcodes.ASM6) { @Override public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { Type[] argumentTypes = Type.getArgumentTypes(descriptor); if (!methodName.equals(name) || !Arrays.equals(argumentTypes, types)) { return super.visitMethod(access, name, descriptor, signature, exceptions); }

                return new MethodVisitor(Opcodes.ASM6) {
                    @Override
                    public void visitLocalVariable(String name, String descriptor, String signature, Label start, Label end,
                            int index) {
                        for (int i = 0; i < lvtSlotIndex.length; i++) {
                            if (lvtSlotIndex[i] == index) {
                                parameterNames[i] = name;
                            }
                        }
                    }
                };
            }
        }, 0);
    } catch (Exception ex) {
        String errorMsg = String.format("Get method parameter names error, method: %s", method.getName());
        throw new DoradoException(errorMsg, ex);
    }`

文件2:/src/main/java/ai/houyi/dorado/rest/util/PackageScanner.java

修改如下: `private static void scanFromJarProtocol(ClassLoader loader, List<Class<?>> classes, String fullPath) throws ClassNotFoundException { final String jar = fullPath.substring(0, fullPath.indexOf('!')); final String parent = fullPath.substring(fullPath.indexOf('!') + 2).replace("!", ""); JarEntry e = null;

    // System.out.println("fullPath:" + fullPath);
    // System.out.println("jar:" + jar);
    // System.out.println("parent:" + parent);
    JarInputStream jarReader = null;
    try {
        jarReader = new JarInputStream(new URL(jar).openStream());
        while ((e = jarReader.getNextJarEntry()) != null) {
            String className = e.getName();
            // System.out.println("className:" + className);
            if (!e.isDirectory() && className.startsWith(parent) && className.endsWith(Constant.CLASS_SUFFIX)
                    && !className.contains("$")) {
                **className = className.replace('/', '.').replace("BOOT-INF.classes.", "");**
                // System.out.println("className:" + className);
                classes.add(loadClass(loader, className));
            }
            jarReader.closeEntry();
        }
    } catch (IOException error) {
        error.printStackTrace();
    } finally {
        try {
            if (jarReader != null)
                jarReader.close();
        } catch (IOException exp) {
            exp.printStackTrace();
        }
    }
}`

很好的项目,感谢!

javagossip commented 4 years ago

我这边尽快修复,因为当时用的时候基本上都不是直接打包成spring-boot这种fat jar来使用,所以这个地方的处理有忽略,我尽快修复