I encountered this exception while building spring MVC file upload example. The error stacktrace looks like this:
java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.getDeclaredMethods(Unknown Source) at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:571) at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:490) at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:474)
Solution
You have incorrect version of apache commons-fileupload. To solve this error, you correct version 1.2.1.
<dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.2.1</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.5</version> </dependency>
This will solve your error.
Happy Learning !!
Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.
thanks!
how to use spring 4 restfull web services for uploading files
https://howtodoinjava.com/spring-mvc/spring-mvc-multi-file-upload-example/