我在 Wildfly 中部署了 EAR 架构:
- 耳朵:
- ejbA.jar
- ejbB.jar
- 库
- LibInterfaceA.jar
- LibInterfaceB.jar
- war
- 库
- LibInterfaceA.jar
- 库
LibInterfaceA.jar 是一个仅在 ejb 模块(A 和 B)以及用于注入(inject) ejb 的 WAR 中使用的接口(interface)的库,并在 LibInterfaceB.jar 中进行了扩展。
当我在 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。 @Custom是WAR/lib/LibInterfaceA.jar
如果我调用此方法来查找实现 LibInterfaceB 接口(interface)的类,该接口(interface)扩展了 LibInterfeceA 中的接口(interface),则该方法上的注释 @Custom 属于 jar EAR/lib/LibInterfaceA.jar ,因此这些类的类加载不同问题。
如何解决这个问题?
最佳答案
您可以从 war 中删除 LibInterfaceA.jar。默认情况下,ear 的子部署可以使用其 lib 目录(除非您在ear的 jboss-depoyment-struct.xml 中设置ear-subdeployments-isolated = true)
关于java - war 的 lib 和 Ear 的 lib 之间的 Wildfly 类加载器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40551536/