Thursday, April 30, 2015

JBoss module dependency error - Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory from [Module "org.springframework.spring:1.0.0" from local module loader

I am using file upload feature in Spring frame work. When I added the following line into web-context.xml ( or application-context.xml).

 <bean id="multipartResolver"   
 class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>  

And then I restarted the web server, I got the following error.

 Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory from [Module "org.springframework.spring:1.0.0" from local module loader @582178a6 (finder: local module finder @7d78077d (roots: C:\act-jboss\jds\runtimes\jboss-eap\modules,C:\act-jboss\jds\runtimes\jboss-eap\modules\system\layers\base))]  
     at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final-redhat-2]  
     at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443) [jboss-modules.jar:1.3.0.Final-redhat-2]  
     at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431) [jboss-modules.jar:1.3.0.Final-redhat-2]  
     at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373) [jboss-modules.jar:1.3.0.Final-redhat-2]  
     at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) [jboss-modules.jar:1.3.0.Final-redhat-2]  
     ... 29 more  

The reason of causing the issue is that my current org.springframework.spring doesn't have the dependence module which should include  org.apache.commons.fileupload.FileItemFactory.

In order to make it work, I create a new module called fileupload under apache/commons.
The structure is as below in my system.



The module.xml is as below.

 <?xml version="1.0" encoding="UTF-8"?>  
 <module xmlns="urn:jboss:module:1.1" name="org.apache.commons.fileupload">  
   <resources>  
     <resource-root path="commons-fileupload-1.3.1.jar"/>  
     <!-- Insert resources here -->  
   </resources>  
   <dependencies>       
        <module name="org.apache.commons.io"/>  
        <module name="javax.servlet.api"/>  
   </dependencies>  
 </module>  

Then, go to springframework, to add fileupload module in to module.xml.



  <module name="org.apache.commons.fileupload" />  
 </dependencies>  


Rebuild and restart the server, Now the error is gone.


No comments:

Post a Comment