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

JavaSpring MvcMaven

Java Problem Overview


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>	

So, can you help me where I am going wrong.

Thanks in advance.

Java Solutions


Solution 1 - Java

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>

Solution 2 - Java

For the security use version 1.4 :

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

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDharmeshView Question on Stackoverflow
Solution 1 - JavajmjView Answer on Stackoverflow
Solution 2 - JavaTomaszView Answer on Stackoverflow