gpt4 book ai didi

java - Spring4配置CommonsMultipartResolver失败

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:12:23 27 4
gpt4 key购买 nike

我在 applicationContext.xml 中配置 CommonsMultipartResolver,如下所示:

<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</bean>

但它抛出如下异常:

15-Feb-2017 22:17:35.049 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
15-Feb-2017 22:17:35.107 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization started
15-Feb-2017 22:17:35.172 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh Refreshing Root WebApplicationContext: startup date [Wed Feb 15 22:17:35 CST 2017]; root of context hierarchy
15-Feb-2017 22:17:35.240 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
15-Feb-2017 22:17:35.563 WARNING [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.refresh Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multipartResolver' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.multipart.commons.CommonsMultipartResolver]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
15-Feb-2017 22:17:35.575 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multipartResolver' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.multipart.commons.CommonsMultipartResolver]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1155)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1099)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
...

不知道为什么CommonsMultipartResolver实例化失败。我可以在 spring-web-4.3.6.RELEASE.jar 中找到 CommonsMultipartResolver。但是抛出了这个异常:

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

我的配置有什么问题?(我使用的是 Intellij IDEA)

更新
这是我的 applicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</bean>
</beans>

我试图通过将 commons-fileupload 添加到 IDEA 项目设置 --> 库来解决这个问题。但这并没有帮助,问题仍然存在。
project structure setting of IDEA

project structure setting of IDEA

最佳答案

下载commons-fileupload并将其保存在容器的模块文件夹中。显然 org.springframework.web.multipart.commons.CommonsMultipartResolver 类对 org.apache.commons.fileupload.FileItemFactory 有硬依赖,这是一个包含在上面的类 jar 。一旦你的容器类加载器加载了这个类,你就不会得到这个错误。

关于java - Spring4配置CommonsMultipartResolver失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42253486/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com