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>
Sign up to request clarification or add additional context in comments.

5 Comments

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 :))
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... :)
Note that these dependencies have to go on the highest artefact classloader (EE types, this is your EAR, not your WAR).
Better narrow down the scope to runtime. <scope>runtime</scope>
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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.