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

Dha*_*esh 58 java spring-mvc maven

我正在尝试使用maven在Spring MVC中进行文件上传的简单示例,然后我将阅读教程.

但是我收到了这个错误

java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
Run Code Online (Sandbox Code Playgroud)

我还在pom.xml中包含了依赖项

<!-- Apache Commons Upload --> 
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>1.3.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

也在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> 
Run Code Online (Sandbox Code Playgroud)

所以,你能帮我解决我的错误吗?

提前致谢.

Jig*_*shi 123

你需要添加 commons-fileupload

将此添加到您的POM

<dependency>
   <groupId>commons-fileupload</groupId>
   <artifactId>commons-fileupload</artifactId>
   <version>1.2.1</version> <!-- makesure correct version here -->
</dependency>
Run Code Online (Sandbox Code Playgroud)