1

I am trying to build a simple Spring MVC Web App with the functionality of file uploading.I got following error:

java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory

After a quick search,all answers pointed to the missing of dependencies,but it seems not to be true in my case:

I have included the following code in pom.xml:

<dependencies> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version> </dependency> </dependencies> with commons.io-2.4.jar and commons.fileupload-1.3.1.jar added into lib folder.

One interesting thing I found was that whenever I deleted the code:

   <bean id="multipartResolver"
      class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="maxUploadSize">
        <value>10000000</value>
    </property>
    <property name="maxInMemorySize">
        <value>10000000</value>
    </property>
  </bean>

the web app works fine(of course I removed the form for file uploading as well. )

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Xuzheng Wang
  • 531
  • 5
  • 17
  • 1
    That class definitely exists in commons-fileupload-1.3.1, so I think you need to double check your deployment to ensure the presence of the jar. – Steve C Jan 06 '16 at 02:21
  • @SteveC Thank you very much!!! The problem is the missing jar file in the deployment. I don't quite understand why the jar file was not automatically included in deployment(I am using intelliJ, I think the jar files in the folder `lib` should be automatically included in artifact) since I have already included them in dependency and they ARE in the lib folder. How could I accept your answer? – Xuzheng Wang Jan 06 '16 at 02:57

2 Answers2

2

If you visit the Maven Central Repository and enter the search term:

fc:org.apache.commons.fileupload.FileItemFactory

then every released artifact available containing that class will be listed.

You will find commons-upload 1.3.1 in that list.

Therefore you need to double check your deployment to ensure that jar is present.

Tip: Use fc: to locate jars in Maven Central that contain a specific class.

Steve C
  • 18,876
  • 5
  • 34
  • 37
0

try to update your jar version, for Example:

    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>2.0.0-SNAPSHOT</version>
    </dependency>

We cann't find versions upper 1.3 on Apache and mvnrepository.com , but you can try this : https://repository.jboss.org/commons-fileupload/commons-fileupload/2.0.0-SNAPSHOT/

In fact, I encountered the same problem and now working fine with version 2.0 under SpringMVC framework.

L.M
  • 21
  • 4