简体   繁体   中英

Class loading issue with JBOSS 6.3.0

I'm running the following class loading issue with JBOSS.

My JBOSS's 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>

When org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapper:getClassIdType(String classId) is called

MessageConversionException: failed to resolve class name... is thrown by

ClassUtils.forName(classId, getClass()
          .getClassLoader())

Debugging getClass().getClassLoader() returns ModuleClassLoader for Module "com.example:main".

So it seems the issue is the class I'm deserializing is not in module com.example (defined in module.xml ) so it throws that exception

My jboss-deployment-structure.xml has com.example as a dependency:

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

I can fix this problem if I remove spring-amqp-1.4.6.RELEASE.jar from module.xml and add spring-amqp to my build.gradle . Problem is module.xml is shared across my org and I can't change that.

So how can I fix this? Appreciate any help.

A stacktrace (and some more code) to reproduce would be nice. I am not familiar with amqp.

In https://github.com/spring-projects/spring-amqp/blob/master/spring-amqp/src/main/java/org/springframework/amqp/support/converter/DefaultJackson2JavaTypeMapper.java at line 56, ClassUtils.forName(classId, getClass().getClassLoader()) gets called, but can't find the class.

In JBoss, module classloaders are seperated from application classloaders. In your application, you can access all classes from the module, but the module can't access your WAR or JAR classes. So, this is exception is thrown, because your module, tries to load a class from your application, which is not visible in the module classloader. But if you add the amqp-jar to your application, it works, because they share the same classloader.

If you want/need amqp in a module, you need to create a module with your application common-classes and add it to your module as a dependency. But also note, you can't add the common.jar to the application.jar anymore to avoid classCastExceptions. I don't know, how amqp is used, but probably, you need to create multiple modules to use it with different common.jars.

For more information about jboss classloading, i can refer you to: http://www.mastertheboss.com/jboss-server/jboss-as-7/discover-jboss-as-7-modularity https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6/html/Development_Guide/chap-Class_Loading_and_Modules.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM