Spring MVC中的java.lang.NoClassDefFoundError:org/apache/commons/fileupload/FileItemFactory [英] java.lang.NoClassDefFoundError:org/apache/commons/fileupload/FileItemFactoryin Spring MVC
问题描述
我正在尝试构建一个具有文件上传功能的简单Spring MVC Web App.出现以下错误:
I am trying to build a simple Spring MVC Web App with the functionality of file uploading.I got following error:
java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
快速搜索后,所有答案都指向缺少依赖项,但在我看来,这并非事实:
After a quick search,all answers pointed to the missing of dependencies,but it seems not to be true in my case:
我在pom.xml中包含了以下代码:
I have included the following code in pom.xml:
<dependencies>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
将commons.io-2.4.jar
和commons.fileupload-1.3.1.jar
添加到lib
文件夹中.
<dependencies>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
with commons.io-2.4.jar
and commons.fileupload-1.3.1.jar
added into lib
folder.
我发现的一件有趣的事是,每当删除代码时:
One interesting thing I found was that whenever I deleted the code:
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>10000000</value>
</property>
<property name="maxInMemorySize">
<value>10000000</value>
</property>
</bean>
该网络应用正常运行(当然,我也删除了用于文件上传的表格.)
the web app works fine(of course I removed the form for file uploading as well. )
推荐答案
如果您访问Maven 中央存储库,并且输入搜索词:
If you visit the Maven Central Repository and enter the search term:
fc:org.apache.commons.fileupload.FileItemFactory
然后将列出每个包含该类的可用工件.
then every released artifact available containing that class will be listed.
您会在该列表中找到commons-upload 1.3.1.
You will find commons-upload 1.3.1 in that list.
因此,您需要仔细检查部署,以确保存在jar.
Therefore you need to double check your deployment to ensure that jar is present.
提示:使用fc:
在Maven Central中找到包含特定类的jar.
Tip: Use fc:
to locate jars in Maven Central that contain a specific class.
这篇关于Spring MVC中的java.lang.NoClassDefFoundError:org/apache/commons/fileupload/FileItemFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!