2011-03-02 109 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