2011-03-02 58 views
53

我正在尝试使用maven在spring MVC中进行文件上传的一个简单示例,并且我对此进行了说明tutorialjava.lang.NoClassDefFoundError:org/apache/commons/fileupload/FileItemFactory

但我收到此错误

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

我还包括在pom.xml中的依赖

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

也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> 

所以,可以你帮我在哪里我错了。

在此先感谢。

回答

104

您需要添加commons-fileupload

添加到您的POM

<dependency> 
    <groupId>commons-fileupload</groupId> 
    <artifactId>commons-fileupload</artifactId> 
    <version>1.2.1</version> <!-- makesure correct version here --> 
</dependency> 
+0

我没有看到玫瑰印度的教程,但也可能是某个地方使用它。做一件事就是将其删除并检查异常或编译错误。并且你总是欢迎的(也是为了回答接受:)) – 2011-03-02 11:47:44

+0

版本1.2.2可用:http://mvnrepository.com/artifact/commons-fileupload/commons-fileupload – 2012-10-01 16:57:46

+0

我有一个类似的tomcat 7开始的问题,通过准备Eclipse控制台日志,我发现我缺少Primefaces fileupload所需的一些jar。添加这些jar即commons-io和commons-fileupload后,我摆脱了tomcat的开始问题...... :) – 2013-01-18 09:11:15