Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JBOSS 6.3.0的类加载问题_Java_Spring_Jboss_Web Deployment_Jboss Eap 6 - Fatal编程技术网

Java JBOSS 6.3.0的类加载问题

Java JBOSS 6.3.0的类加载问题,java,spring,jboss,web-deployment,jboss-eap-6,Java,Spring,Jboss,Web Deployment,Jboss Eap 6,我正在用JBOSS运行下面的类加载问题 My JBOSS的module.xml: <module xmlns="urn:jboss:module:1.0" name="com.example"> <resources> ... <resource-root path="spring-amqp-1.4.6.RELEASE.jar"/> ... </resources> </module

我正在用JBOSS运行下面的类加载问题

My JBOSS的module.xml:

<module xmlns="urn:jboss:module:1.0" name="com.example">
  <resources>
        ...
        <resource-root path="spring-amqp-1.4.6.RELEASE.jar"/>
        ...
  </resources>  
</module>
调试
getClass().getClassLoader()
返回模块“com.example:main”的
ModuleClassLoader.

因此,问题似乎是我正在反序列化的类不在module
com.example
(在
module.xml
中定义)中,因此它引发了该异常

我的
jboss部署结构.xml
依赖于
com.example

 <dependencies>
            <module name="com.example">
                <imports>
                    <include path="META-INF**"/>
                </imports>
            </module>
        </dependencies>

如果我从
module.xml
中删除
spring-amqp-1.4.6.RELEASE.jar
,并将
spring-amqp
添加到我的
build.gradle
,我就可以解决这个问题。问题是
module.xml
在我的组织中是共享的,我不能改变这一点

那么我该如何解决这个问题呢?感谢您的帮助。

一个stacktrace(以及更多的代码)可以复制。我不熟悉amqp

在第56行,调用ClassUtils.forName(classId,getClass().getClassLoader()),但找不到该类

在JBoss中,模块类加载器与应用程序类加载器是分开的。在应用程序中,您可以从模块访问所有类,但模块无法访问WAR或JAR类。 所以,抛出这个异常是因为您的模块试图从应用程序加载一个类,而这个类在模块类加载器中不可见。但是,如果您将amqp jar添加到应用程序中,它就会工作,因为它们共享同一个类加载器

如果希望/需要模块中的amqp,则需要使用应用程序公共类创建一个模块,并将其作为依赖项添加到模块中。但是还要注意,您不能再将common.jar添加到application.jar中,以避免ClassCastException。 我不知道amqp是如何使用的,但您可能需要创建多个模块来使用不同的common.jar

有关jboss类加载的更多信息,请参阅:

你的回答让我明白了很多,但我还是有点迷茫。JBOSS中的
module.xml
是共享的,因此我无法修改它。那么,有没有办法告诉JBOSS
JBOSS部署结构
使用我的应用程序的模块来加载amqp,而不是普通的(
com.example
)模块呢?我很确定,如果不修改module.xml,您就没有机会解决这个问题。为什么你需要使用一个模块,也许你可以问问你的大学或系统架构师,他们是否做过概念证明。或者添加jar,而不通过添加jboss-deployment-structure.xml来添加模块,我不推荐这样做
 <dependencies>
            <module name="com.example">
                <imports>
                    <include path="META-INF**"/>
                </imports>
            </module>
        </dependencies>