2017-02-15 3 views
1

ich konfigurieren CommonsMultipartResolver in applicationContext.xml wie folgt vor:Ausfallen konfigurieren CommonsMultipartResolver in Spring4

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

aber es wirft Ausnahme, wie folgend:

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) 
    ... 

ich bekannt nicht, warum CommonsMultipartResolver sein gescheitert instanziiert. Ich kann CommonsMultipartResolver in spring-web-4.3.6.RELEASE.jar finden. Aber diese Ausnahme ausgelöst wird:

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

Was mit meiner Konfiguration falsch

UPDATE
das ist mein 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> 
(ich IntelliJ IDEA bin mit)

Ich habe versucht, das Problem zu lösen, indem Sie commons-fileupload IDEA Projekteinstellungen hinzufügen -> li Braries. Aber es hilft nicht, Probleme noch.
project structure setting of IDEA

project structure setting of IDEA

+0

Zeigen Sie uns Ihre vollständige applicationContext.xml und wenn möglich einen Teil Ihres Java-Codes, der auf 'FileItemFactory' verweist. – VHS

+0

ok, ich füge es einfach zu UPDATE hinzu. Mein Java-Code verweist nie auf 'FileItemFactory' 'CommonsMultipartResolver' kann auf –

Antwort

1

Herunterladen commons-fileupload und halten Sie sie in Ihre Module Ordner des Containers. Anscheinend hat die Klasse org.springframework.web.multipart.commons.CommonsMultipartResolver eine harte Abhängigkeit von org.apache.commons.fileupload.FileItemFactory, die eine Klasse ist, die in dem obigen Jar enthalten ist. Sobald Ihr Container-Klassenlader diese Klasse lädt, erhalten Sie diesen Fehler nicht.

+0

verweisen Ich habe versucht, es zu meinem IDEA-Projekt hinzuzufügen, indem ich es zu Projektbibliotheken hinzufüge, wie ich in ** UPDATE ** beschrieben habe, aber es hilft nicht. Ich bin wirklich verwirrt. –

+0

Oh, es ist meine Schuld. Ich habe gerade das Problem gefunden. Ich habe vergessen, das Archiv 'org.apache.commons.fileupload.FileItemFactory' zu meinen Artefakten (.war) hinzuzufügen. Ich füge es hinzu, indem ich 'project structrue' ->' project settings' -> 'artifacts' ->' output layout' konfiguriere –