69

I am trying a simple example of file upload in spring MVC using maven and I follwed this tutorial.

But I am getting this error

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

I also included the dependencies in pom.xml

<!-- Apache Commons Upload --> 
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>1.3.2</version>
</dependency>

also in dispatcher-servlet.xml

<!-- Configure the multipart resolver -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <!-- one of the properties available; the maximum file size in bytes -->
    <property name="maxUploadSize" value="100000"/>
</bean> 

Where I am going wrong?

0

2 Answers 2

147

You need to add commons-fileupload

add this to your POM

<dependency>
   <groupId>commons-fileupload</groupId>
   <artifactId>commons-fileupload</artifactId>
   <version>1.2.1</version> <!-- makesure correct version here -->
</dependency>
5
  • I haven't read the rose india's tutorial, but it might be using it somewhere. do one thing just remove it and check for exception or compilation error. and you are always welcome (also to mark answer accepted :)) Commented Mar 2, 2011 at 11:47
  • version 1.2.2 available: mvnrepository.com/artifact/commons-fileupload/…
    – Adriano
    Commented Oct 1, 2012 at 16:57
  • I had a similar tomcat 7 starting issue, by ready the Eclipse console logs, I found out that I was missing some jars needed by Primefaces fileupload. After adding those jars i.e. commons-io and commons-fileupload, I got rid of the tomcat starting issue... :) Commented Jan 18, 2013 at 9:11
  • Note that these dependencies have to go on the highest artefact classloader (EE types, this is your EAR, not your WAR).
    – 8bitjunkie
    Commented Jun 5, 2013 at 13:34
  • Better narrow down the scope to runtime. <scope>runtime</scope>
    – Vic
    Commented Jun 17, 2013 at 14:51
2

For the security use version 1.5 :

<dependency>
   <groupId>commons-fileupload</groupId>
   <artifactId>commons-fileupload</artifactId>
   <version>1.5</version>
</dependency>

Check : https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.