有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

war库和ear库之间的java wildfly类加载器问题

我在Wildfly中部署了EAR的模式:

  • 耳朵:
    • 埃伊巴。罐子
    • ejbB。罐子
    • 解放党
      • 利比亚。罐子
      • libb。罐子
    • 战争
      • 解放党
        • 利比亚。罐子

利比亚。jar是一个仅用于ejb模块(a adn B)和WAR中的接口库,用于注入ejb并在LibInterfaceB中扩展。罐子

当我在LibInterfaceA中搜索自定义注释时,java反射存在问题:

public Annotation getAnnotazione(Method method, Class annotationType){
    Annotation annotazioni[] = method.getAnnotations();
    URL locationsearch = annotationType.getResource('/' + annotationType.getName().replace('.', '/') + ".class");
    for(Annotation a : annotazioni){
        Class klass = a.annotationType();
        URL location = klass.getResource('/' + klass.getName().replace('.', '/') + ".class");
        if(a.annotationType().getName().equals(annotationType.getName())){
            return a;
        }
    }
    return null;
}

我在WAR中的一个类中调用此方法以查找注释annotationType=@Custom@习惯是战争/自由/自由的。罐子

如果我调用此方法查找实现LibInterfaceB接口的类,该接口扩展LibInterfeceA中的接口,则方法上的注释@Custom是jar EAR/lib/libinterfaceea。jar,所以类加载问题的类是不同的

我怎样才能解决这个问题


共 (1) 个答案

  1. # 1 楼答案

    你可以删除libea。从战争中解脱出来。默认情况下,ear的子部署可以使用其lib目录(除非您在ear的jboss-depoyment-structure.xml中将ear子部署隔离设置为true)