CommonsMultipartResolver

CommonsMultipartResolver

本文介绍了所需的MultipartFile参数“文件”不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Spring Boot来测试上传功能,并且获取
'所需的MultipartFile参数'文件'不存在'
错误。以下是1)JSP,2)控制器3)配置类4)嵌入式tomcat日志。


  1. JSP页面

      ------------------------------------------------- --------------------------- 
    <!DOCTYPE html>


    < html lang =en>

    < body>
    消息:$ {消息}
    < h2>对象列表< / h2>

    < br>
    < h2>将新文件上传至此存储桶< / h2>
    < form action =uploadObjectmethod =postenctype =multipart / form-data>
    < table width =60%border =1cellspacing =0>
    < tr>
    < td width =35%>< strong>上传档案< / strong>< / td>
    < td width =65%>< input type =filename =file/>< / td>
    < / tr>
    < tr>
    < td>& nbsp;< / td>
    < td>< input type =submitname =submitvalue =Add/>< / td>
    < / tr>
    < / table>
    < / form>
    < / body>
    < / html>




Controller:

  @RequestMapping(value =/ uploadObject,method = RequestMethod.POST)
@Override
public String upload(@RequestParam(file)MultipartFile file,
@RequestParam(bucketName)String bucketName,
Map< String,Object> model){

LOG.info(对象名称参数是+ file.getOriginalFilename());
LOG.info(桶名参数是+ bucketName);
...

code
$ b 3)配置类:

  package com.phi.piranha.client.config; 

import javax.servlet.MultipartConfigElement;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.MultiPartConfigFactory;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

@Configuration
@EnableAutoConfiguration
@ComponentScan(com.phi.piranha)
public class PiranhaStorageServiceClientApplication extends
SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(
final SpringApplicationBuilder应用程序){
返回应用程序
.sources(PiranhaStorageServiceClientApplication.class);

$ b @SuppressWarnings(PMD.SignatureDeclareThrowsException)
public static void main(final String [] args)throws Exception {
SpringApplication.run(PiranhaStorageServiceClientApplication。类,
args);

$ b @Bean
MultipartConfigElement multipartConfigElement(){
MultiPartConfigFactory factory = new MultiPartConfigFactory();
factory.setMaxFileSize(1024KB);
factory.setMaxRequestSize(1024KB);
return factory.createMultipartConfig();


$Be
CommonsMultipartResolver multipartResolver(){
return new CommonsMultipartResolver();






$ 4 $ Emaded Tomcat log:$ / $

 。 (_)_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ '_'|'_ \ / _` | \\\\ 
\\ / ___)| | _)| | | | | || (_ | |))))
'| ____ | .__ | _ | | _ | _ | | _\__,| / / / /
========= | _ | ============== | ___ / = / _ / _ / _ /
: :Spring Boot ::(v1.0.0.RC4)

2014-03-28 14:41:01.216 INFO 2852 --- [main] c.PiranhaStorageServiceClientApplication:在PID 2852的USDSFOSFC1NBOPY上启动PiranhaStorageServiceClientApplication C:\\\\workspace\sandbox\s3-poc-client\target\classes由310152252开始)
2014-03-28 14:41:01.220 DEBUG 2852 --- [main] osboot.SpringApplication:加载源类com.phi.piranha.client.config.PiranhaStorageServiceClientApplication
2014-03-28 14:41:01.270 INFO 2852 --- [main] ationConfigEmbeddedWebApplicationContext:刷新org.springframework.boot。 context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6f434304:启动日期[Fri Mar 28 14:41:01 PDT 2014];上下文层次结构的根
2014-03-28 14:41:01.273 DEBUG 2852 --- [main] ationConfigEmbeddedWebApplicationContext:org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6f434304的Bean工厂:org.springframework.beans .factory.support.DefaultListableBeanFactory @ 62b08658:定义bean [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation。 internalCommonAnnotationProcessor,piranhaStorageServiceClientApplication];工厂层次结构的根
2014-03-28 14:41:01.897 INFO 2852 --- [main] o.s.b.f.s.DefaultListableBeanFactory:为bean'multipartResolver'重写bean定义:替换[Root bean:class [null];范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 3; dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE; factoryBeanName = piranhaStorageServiceClientApplication; factoryMethodName = multipartResolver; initMethodName = NULL; destroyMethodName =(推断);定义在类com.phi.piranha.client.config.PiranhaStorageServiceClientApplication]中,其中[Root bean:class [null];范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 3; dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE; factoryBeanName = org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration; factoryMethodName = multipartResolver; initMethodName = NULL; destroyMethodName =(推断);定义在类路径资源中[org / springframework / boot / autoconfigure / web / MultipartAutoConfiguration.class]]
2014-03-28 14:41:02.188 DEBUG 2852 --- [main] ationConfigEmbeddedWebApplicationContext:使用MessageSource [ springframework.context.support.ResourceBundleMessageSource:basenames = [messages]]
2014-03-28 14:41:02.189 DEBUG 2852 --- [main] ationConfigEmbeddedWebApplicationContext:使用ApplicationEventMulticaster [org.springframework.context.event.SimpleApplicationEventMulticaster @ 58a1c2bf]
2014-03-28 14:41:02.495 DEBUG 2852 --- [main] .t.TomcatEmbeddedServletContainerFactory:代码存档:C:\ Users \ 310122252\.m2\repository\ org\springframework\boot\spring-boot\1.0.0.RC4\spring-boot-1.0.0.RC4.jar
2014-03-28 14:41:02.495 DEBUG 2852 - - [main] .t.TomcatEmbeddedServletContainerFactory:代码存档:C:\ Users \\\\\\\\\\\\\\\\' \\ springframework \ boot \spring-boot\1.0.0.RC4\spring-boot-1.0.0.RC4.jar
2014-03-28 14:41:02.496 DEBUG 2852 --- [主] .t.TomcatEmbeddedServletContainerFactory:文档根:C:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 02.546 INFO 2852 --- [main] .t.TomcatEmbeddedServletContainerFactory:服务器用端口初始化:9090
2014-03-28 14:41:02.884 INFO 2852 --- [main] o.apache.catalina.core。 StandardService:开始服务Tomcat
2014-03-28 14:41:02.885信息2852 --- [main] org.apache.catalina.core.StandardEngine:启动Servlet引擎:Apache Tomcat / 7.0.52
2014-03-28 14:41:03.077 INFO 2852 --- [ost-startStop-1] oaccC [Tomcat]。[localhost]。[/]:初始化Spring嵌入式WebApplicationContext
2014-03-28 14 :41:03.077 INFO 2852 --- [ost-startStop-1] osweb.context.ContextLoader:Root WebApplicatio nContext:初始化在1811年完成ms
2014-03-28 14:41:03.810 INFO 2852 --- [ost-startStop-1] osbceServletRegistrationBean:将servlet:'dispatcherServlet'映射到[/]
2014-03-28 14:41:03.813 INFO 2852 --- [ost-startStop-1] osbcembedded.FilterRegistrationBean:映射过滤器:'hiddenHttpMethodFilter'到:[/ *]
2014-03-28 14: 41:04.356 INFO 2852 --- [main] oswshandler.SimpleUrlHandlerMapping:映射的URL路径[/**/favicon.ico]到[class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]类型的处理程序
2014-03-28 14:41:04.483 INFO 2852 --- [main] oswshandler.SimpleUrlHandlerMapping:将URL路径映射到[class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]类型的处理程序上
2014-03-28 14:41:04.483 INFO 2852 --- [main] oswshandler.SimpleUrlHandlerMapping:映射的URL路径[/ webjars / **]到[class org.springframework .web.servlet.resource.ResourceHttpRequestHandler]
2014-03-28 14:41:04.744信息2852 --- [main] osjeaAnnotationMBeanExporter:在启​​动时为JMX注册bean注册
2014-03-28 14:41:04.763 DEBUG 2852 --- [main] ationConfigEmbeddedWebApplicationContext:无法找到名称为lifecycleProcessor的LifecycleProcessor:using default [org.springframework.context.support.DefaultLifecycleProcessor@11a91abc]
2014-03-28 14 :41:04.765 DEBUG 2852 --- [main] utoConfigurationReportLoggingInitializer:


======================== =
AUTO-CONFIGURATION REPORT
=========================


正匹配:
-----------------

MessageSourceAutoConfiguration
- @ConditionalOnMissingBean(类型:org.springframework.context.MessageSource ; SearchStrategy:all)找不到bean(OnBeanCondition)
$ b PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer
- @ConditionalOnMissingBean(types:org.springframework.context.support.PropertySourcesPlaceholderConfigurer; SearchStrategy:current)found no beans(OnBeanCondition) )

JmxAutoConfiguration
- 找到@ConditionalOnClass类:org.springframework.jmx.export.MBeanExporter(OnClassCondition)
- org.springframework.boot.autoconfigure.jmx上的SpEL表达式。 JmxAutoConfiguration:$ {spring.jmx.enabled:true}(OnExpressionCondition)
- @ConditionalOnMissingBean(类型:org.springframework.jmx.export.MBeanExporter; SearchStrategy:全部)找不到bean(OnBeanCondition)

DispatcherServletAutoConfiguration
- 找到web应用程序StandardServletEnvironment(OnWebApplicationCondition)
- 找到@ConditionalOnClass类:org.springframework.web.servlet.DispatcherServlet (OnClassCondition)

DispatcherServletAutoConfiguration.DispatcherServletConfiguration
- no找到DispatcherServlet(DispatcherServletAutoConfiguration.DefaultDispatcherServletCondition)
- 找到@ConditionalOnClass类:javax.servlet.ServletRegistration(OnClassCondition)

EmbeddedServletContainerAutoConfiguration
- 找到的Web应用程序StandardServletEnvironment(OnWebApplicationCondition)

EmbeddedServletContainerAutoConfiguration.EmbeddedTomcat
- 找到@ConditionalOnClass类:javax.servlet.Servlet,org.apache.catalina.startup .Tomcat(OnClassCondition)
- @ConditionalOnMissingBean(类型:org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; SearchStrategy:current)找不到bean(OnBeanCondition)

HttpMessageConvertersAutoConfiguration
- 找到@ConditionalOnClass类:org.springframework.http.converter.HttpMessageConverter(OnClassCondition)

HttpMessageConvertersAutoConfiguration #messageConverters
- @ConditionalOnMissingBean(类型:org.springframework.boot.autoconfigure.web.HttpMessageConverters; SearchStrategy:全部)找不到bean(OnBeanCondition)

HttpMessageConvertersAutoConfiguration.ObjectMappers
- @ConditionalOnClass类找到:com.fasterxml.jackson.databind.ObjectMapper(OnClassCondition)

HttpMessageConvertersAutoConfiguration.ObjectMappers#jacksonObjectMapper
- @ConditionalOnMissingBean(类型:com.fasterxml.jackson.databind.ObjectMapper; SearchStrategy:all)找不到bean(OnBeanCondition)

HttpMessageConvertersAutoConfiguration.ObjectMappers#mappingJackson2HttpMessageConverter
- @ ConditionalOnMissingBean(类型:org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; SearchStrategy:all)找不到bean(OnBeanCondition)

MultipartAutoConfiguration
- 找到@ConditionalOnClass类:javax.servlet.Servlet,org.springframework.web.multipart.support.StandardServletMultipartResolver(OnClassCondition)
- @ConditionalOnBean(类型:javax.servlet.MultipartConfigElement; SearchStrategy:all)找到以下[multipartConfigElement](OnBeanCondition)

ServerPropertiesAutoConfiguration
- 找到的web应用程序StandardServletEnvironment(OnWebApplicationCondition)

ServerPropertiesAutoConfiguration#serverProperties
- @ConditionalOnMissingBean(类型:org.springframework.boot.autoconfigure.web.ServerProperties; SearchStrategy:current)找不到bean(OnBeanCondition)

WebMvcAutoConfiguration
- 找到Web应用程序StandardServletEnvironment(OnWebApplicationCondition)
- 找到@ConditionalOnClass类:javax.servlet.Servlet,org.springfr org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter(OnClassCondition)
- @ConditionalOnMissingBean(类型:org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; SearchStrategy:all)没有找到bean(OnBeanCondition)

WebMvcAutoConfiguration#hiddenHttpMethodFilter $ b $ - @ConditionalOnMissingBean(类型:org.springframework.web.filter.HiddenHttpMethodFilter; SearchStrategy:all) )

WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#defaultViewResolver
- @ConditionalOnMissingBean(类型:org.springframework.web.servlet.view.InternalResourceViewResolver; SearchStrategy:全部)找不到bean(OnBeanCondition)

WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#requestContextListener
- @ConditionalOnMissingBean(类型:org.springframework.web.context.request.RequestContextListener; SearchStrategy:全部)找不到bean(OnBeanCondition)


否定匹配:
-----------------

RabbitAutoConfiguration
- 必需的@ConditionalOnClass找不到的类:org。 springframework.amqp.rabbit.core.RabbitTemplate,com.ra bbitmq.client.Channel(OnClassCondition)

AopAutoConfiguration
- 必需的@ConditionalOnClass类未找到:org.aspectj.lang.annotation.Aspect,org.aspectj.lang.reflect.Advice(OnClassCondition )

BatchAutoConfiguration
- 必需的@ConditionalOnClass类未找到:org.springframework.batch.core.launch.JobLauncher,org.springframework.jdbc.core.JdbcOperations(OnClassCondition)

JpaRepositoriesAutoConfiguration
- 必需@ConditionalOnClass类未找到:org.springframework.data.jpa.repository.JpaRepository(OnClassCondition)

MongoRepositoriesAutoConfiguration
- 必需的@ConditionalOnClass类不是发现:com.mongodb.Mongo,org.springframework.data.mongodb.repository.MongoRepository(OnClassCondition)

MongoTemplateAutoConfiguration
- 必需的@ConditionalOnClass类未找到:com.mongodb.Mongo,org .springframework.data.mongodb.core.MongoTemplate( OnClassCondition)

DataSourceAutoConfiguration
- 必填@ConditionalOnClass类未找到:org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType(OnClassCondition)

DataSourceTransactionManagerAutoConfiguration
- 必需的@ConditionalOnClass类未找到:org.springframework.jdbc.core.JdbcTemplate,org.springframework.transaction.PlatformTransactionManager(OnClassCondition)

JmsTemplateAutoConfiguration $ b $ - 必需的@ConditionalOnClass未找到类:org .springframework.jms.core.JmsTemplate,javax.jms.ConnectionFactory(OnClassCondition)

DeviceResolverAutoConfiguration
- 必需的@ConditionalOnClass类未找到:org.springframework.mobile.device.DeviceResolverHandlerInterceptor,org。 springframework.mobile.device.DeviceHandlerMethodArgumentResolver(OnClassCondition)

MongoAutoConfiguration
- 必需的@ConditionalOnClass类未找到: (HibernateJpaAutoConfiguration.HibernateEntityManagerCondition)

ReactorAutoConfiguration
- 必需的@ConditionalOnClass类找不到:reactor.spring.context.config.EnableReactor(OnClassCondition)

RedisAutoConfiguration $ b $ - 必需@ConditionalOnClass类未找到:org.springframework.data.redis.connection.lettuce.LettuceConnection, org.springframework.data.redis.core.RedisOperations,com.lambdaworks.redis.RedisClient(OnClassCondition)

SecurityAutoConfiguration
- 必需的@ConditionalOnClass类未找到:org.springframework.security.authentication .AuthenticationManager(OnClassCondition)

ThymeleafAutoConfiguration
- 必需的@ConditionalOnClass类未找到:org.thymeleaf.spring4.SpringTemplateEngine(OnClassCondition)

E org.eclipse.jetty.server.Server,org.eclipse.jetty.util.Loader(OnClassCondition)

WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#beanNameViewResolver
- @ConditionalOnBean(类型:org.springframework.web.servlet.View; SearchStrategy:all)找不到bean(OnBeanCondition)

WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#viewResolver
- @ConditionalOnBean(类型:org.springframework.web.servlet.View; SearchStrategy:all)found no beans (OnBeanCondition)

WebSocketAutoConfiguration
- 必填@ConditionalOnClass类未找到:org.springframework.web.socket.WebSocketHandler(OnClassCondition)



2014-03-28 14:41:04.821 INFO 2852 --- [main] sbcetTomcatEmbeddedServletContainer:Tomcat启动端口:9090
2014-03-28 14:41:04.829 INFO 2852 --- [main ] c.PiranhaStorageServiceClientApplication:在4.231秒内启动PiranhaStorageServiceClientApplication(JVM运行5.249)


解决方案

我发现在Spring引导中有一个MultipartAutoConfiguration问题。我禁用它,并添加@Bean在网络配置,它的工作。根据例外情况,我看到Jackson Mapper试图解析多部分内容,而不是多部分解析器本身。



以下是摘录。

  @EnableAutoConfiguration(exclude = {MultipartAutoConfiguration.class} 

在您的webconfig类中添加以下内容:


$ b $ public class WebConfig extends WebMvcConfigurerAdapter {

$Be $($ $ $ $ $ $ $ $ CommonsMultipartResolver multipartResolver $)
Common CommonsMultipartResolver multipartResolver(){
logger.info(加载多重解析器);
CommonsMultipartResolver multipartResolver
= new CommonsMultipartResolver();
返回multipartResolver;
}


I am using Spring Boot to test a upload functionality, and getting'Required MultipartFile parameter 'file' is not present'error. Following are the 1) JSP, 2) Controller 3) Config Class 4) embedded tomcat log.

  1. JSP page

    ----------------------------------------------------------------------------
    <!DOCTYPE html>
    
    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    
    <html lang="en">
    
    <body>
        <br>Message: ${message}
        <h2>List Of Objects</h2>
    
        <br>
        <h2>Upload New File to this Bucket</h2>
        <form action="uploadObject" method="post" enctype="multipart/form-data">
            <table width="60%" border="1" cellspacing="0">
                <tr>
                    <td width="35%"><strong>File to upload</strong></td>
                    <td width="65%"><input type="file" name="file" /></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td><input type="submit" name="submit" value="Add" /></td>
                </tr>
            </table>
        </form>
    </body>
    </html>
    

2. Controller:

@RequestMapping(value = "/uploadObject", method = RequestMethod.POST)
    @Override
    public String upload(@RequestParam("file") MultipartFile file,
            @RequestParam("bucketName") String bucketName,
            Map<String, Object> model) {

        LOG.info("Object name parameter is " + file.getOriginalFilename());
        LOG.info("Bucket name parameter is " + bucketName);
....
}

3) Config Class:

package com.phi.piranha.client.config;

import javax.servlet.MultipartConfigElement;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.MultiPartConfigFactory;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

@Configuration
@EnableAutoConfiguration
@ComponentScan("com.phi.piranha")
public class PiranhaStorageServiceClientApplication extends
        SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(
            final SpringApplicationBuilder application) {
        return application
                .sources(PiranhaStorageServiceClientApplication.class);
    }

    @SuppressWarnings("PMD.SignatureDeclareThrowsException")
    public static void main(final String[] args) throws Exception {
        SpringApplication.run(PiranhaStorageServiceClientApplication.class,
                args);
    }

    @Bean
    MultipartConfigElement multipartConfigElement() {
        MultiPartConfigFactory factory = new MultiPartConfigFactory();
        factory.setMaxFileSize("1024KB");
        factory.setMaxRequestSize("1024KB");
        return factory.createMultipartConfig();
    }

    @Bean
    CommonsMultipartResolver multipartResolver(){
        return new CommonsMultipartResolver();
    }
}

4) Emedded Tomcat log:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::            (v1.0.0.RC4)

2014-03-28 14:41:01.216  INFO 2852 --- [           main] c.PiranhaStorageServiceClientApplication : Starting PiranhaStorageServiceClientApplication on USDSFOSFC1NBOPY with PID 2852 (C:\a\workspace\sandbox\s3-poc-client\target\classes started by 310152252)
2014-03-28 14:41:01.220 DEBUG 2852 --- [           main] o.s.boot.SpringApplication               : Loading source class com.phi.piranha.client.config.PiranhaStorageServiceClientApplication
2014-03-28 14:41:01.270  INFO 2852 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6f434304: startup date [Fri Mar 28 14:41:01 PDT 2014]; root of context hierarchy
2014-03-28 14:41:01.273 DEBUG 2852 --- [           main] ationConfigEmbeddedWebApplicationContext : Bean factory for org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6f434304: org.springframework.beans.factory.support.DefaultListableBeanFactory@62b08658: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,piranhaStorageServiceClientApplication]; root of factory hierarchy
2014-03-28 14:41:01.897  INFO 2852 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'multipartResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=piranhaStorageServiceClientApplication; factoryMethodName=multipartResolver; initMethodName=null; destroyMethodName=(inferred); defined in class com.phi.piranha.client.config.PiranhaStorageServiceClientApplication] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration; factoryMethodName=multipartResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.class]]
2014-03-28 14:41:02.188 DEBUG 2852 --- [           main] ationConfigEmbeddedWebApplicationContext : Using MessageSource [org.springframework.context.support.ResourceBundleMessageSource: basenames=[messages]]
2014-03-28 14:41:02.189 DEBUG 2852 --- [           main] ationConfigEmbeddedWebApplicationContext : Using ApplicationEventMulticaster [org.springframework.context.event.SimpleApplicationEventMulticaster@58a1c2bf]
2014-03-28 14:41:02.495 DEBUG 2852 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Code archive: C:\Users\310152252\.m2\repository\org\springframework\boot\spring-boot\1.0.0.RC4\spring-boot-1.0.0.RC4.jar
2014-03-28 14:41:02.495 DEBUG 2852 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Code archive: C:\Users\310152252\.m2\repository\org\springframework\boot\spring-boot\1.0.0.RC4\spring-boot-1.0.0.RC4.jar
2014-03-28 14:41:02.496 DEBUG 2852 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Document root: C:\a\workspace\sandbox\s3-poc-client\src\main\webapp
2014-03-28 14:41:02.546  INFO 2852 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 9090
2014-03-28 14:41:02.884  INFO 2852 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2014-03-28 14:41:02.885  INFO 2852 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.52
2014-03-28 14:41:03.077  INFO 2852 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2014-03-28 14:41:03.077  INFO 2852 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1811 ms
2014-03-28 14:41:03.810  INFO 2852 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2014-03-28 14:41:03.813  INFO 2852 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2014-03-28 14:41:04.356  INFO 2852 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-03-28 14:41:04.483  INFO 2852 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-03-28 14:41:04.483  INFO 2852 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-03-28 14:41:04.744  INFO 2852 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2014-03-28 14:41:04.763 DEBUG 2852 --- [           main] ationConfigEmbeddedWebApplicationContext : Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@11a91abc]
2014-03-28 14:41:04.765 DEBUG 2852 --- [           main] utoConfigurationReportLoggingInitializer :


=========================
AUTO-CONFIGURATION REPORT
=========================


Positive matches:
-----------------

   MessageSourceAutoConfiguration
      - @ConditionalOnMissingBean (types: org.springframework.context.MessageSource; SearchStrategy: all) found no beans (OnBeanCondition)

   PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer
      - @ConditionalOnMissingBean (types: org.springframework.context.support.PropertySourcesPlaceholderConfigurer; SearchStrategy: current) found no beans (OnBeanCondition)

   JmxAutoConfiguration
      - @ConditionalOnClass classes found: org.springframework.jmx.export.MBeanExporter (OnClassCondition)
      - SpEL expression on org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration: ${spring.jmx.enabled:true} (OnExpressionCondition)
      - @ConditionalOnMissingBean (types: org.springframework.jmx.export.MBeanExporter; SearchStrategy: all) found no beans (OnBeanCondition)

   DispatcherServletAutoConfiguration
      - found web application StandardServletEnvironment (OnWebApplicationCondition)
      - @ConditionalOnClass classes found: org.springframework.web.servlet.DispatcherServlet (OnClassCondition)

   DispatcherServletAutoConfiguration.DispatcherServletConfiguration
      - no DispatcherServlet found (DispatcherServletAutoConfiguration.DefaultDispatcherServletCondition)
      - @ConditionalOnClass classes found: javax.servlet.ServletRegistration (OnClassCondition)

   EmbeddedServletContainerAutoConfiguration
      - found web application StandardServletEnvironment (OnWebApplicationCondition)

   EmbeddedServletContainerAutoConfiguration.EmbeddedTomcat
      - @ConditionalOnClass classes found: javax.servlet.Servlet,org.apache.catalina.startup.Tomcat (OnClassCondition)
      - @ConditionalOnMissingBean (types: org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; SearchStrategy: current) found no beans (OnBeanCondition)

   HttpMessageConvertersAutoConfiguration
      - @ConditionalOnClass classes found: org.springframework.http.converter.HttpMessageConverter (OnClassCondition)

   HttpMessageConvertersAutoConfiguration#messageConverters
      - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.web.HttpMessageConverters; SearchStrategy: all) found no beans (OnBeanCondition)

   HttpMessageConvertersAutoConfiguration.ObjectMappers
      - @ConditionalOnClass classes found: com.fasterxml.jackson.databind.ObjectMapper (OnClassCondition)

   HttpMessageConvertersAutoConfiguration.ObjectMappers#jacksonObjectMapper
      - @ConditionalOnMissingBean (types: com.fasterxml.jackson.databind.ObjectMapper; SearchStrategy: all) found no beans (OnBeanCondition)

   HttpMessageConvertersAutoConfiguration.ObjectMappers#mappingJackson2HttpMessageConverter
      - @ConditionalOnMissingBean (types: org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; SearchStrategy: all) found no beans (OnBeanCondition)

   MultipartAutoConfiguration
      - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.multipart.support.StandardServletMultipartResolver (OnClassCondition)
      - @ConditionalOnBean (types: javax.servlet.MultipartConfigElement; SearchStrategy: all) found the following [multipartConfigElement] (OnBeanCondition)

   ServerPropertiesAutoConfiguration
      - found web application StandardServletEnvironment (OnWebApplicationCondition)

   ServerPropertiesAutoConfiguration#serverProperties
      - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.web.ServerProperties; SearchStrategy: current) found no beans (OnBeanCondition)

   WebMvcAutoConfiguration
      - found web application StandardServletEnvironment (OnWebApplicationCondition)
      - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.servlet.DispatcherServlet,org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter (OnClassCondition)
      - @ConditionalOnMissingBean (types: org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; SearchStrategy: all) found no beans (OnBeanCondition)

   WebMvcAutoConfiguration#hiddenHttpMethodFilter
      - @ConditionalOnMissingBean (types: org.springframework.web.filter.HiddenHttpMethodFilter; SearchStrategy: all) found no beans (OnBeanCondition)

   WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#defaultViewResolver
      - @ConditionalOnMissingBean (types: org.springframework.web.servlet.view.InternalResourceViewResolver; SearchStrategy: all) found no beans (OnBeanCondition)

   WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#requestContextListener
      - @ConditionalOnMissingBean (types: org.springframework.web.context.request.RequestContextListener; SearchStrategy: all) found no beans (OnBeanCondition)


Negative matches:
-----------------

   RabbitAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.amqp.rabbit.core.RabbitTemplate,com.rabbitmq.client.Channel (OnClassCondition)

   AopAutoConfiguration
      - required @ConditionalOnClass classes not found: org.aspectj.lang.annotation.Aspect,org.aspectj.lang.reflect.Advice (OnClassCondition)

   BatchAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.batch.core.launch.JobLauncher,org.springframework.jdbc.core.JdbcOperations (OnClassCondition)

   JpaRepositoriesAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.data.jpa.repository.JpaRepository (OnClassCondition)

   MongoRepositoriesAutoConfiguration
      - required @ConditionalOnClass classes not found: com.mongodb.Mongo,org.springframework.data.mongodb.repository.MongoRepository (OnClassCondition)

   MongoTemplateAutoConfiguration
      - required @ConditionalOnClass classes not found: com.mongodb.Mongo,org.springframework.data.mongodb.core.MongoTemplate (OnClassCondition)

   DataSourceAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType (OnClassCondition)

   DataSourceTransactionManagerAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.jdbc.core.JdbcTemplate,org.springframework.transaction.PlatformTransactionManager (OnClassCondition)

   JmsTemplateAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.jms.core.JmsTemplate,javax.jms.ConnectionFactory (OnClassCondition)

   DeviceResolverAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.mobile.device.DeviceResolverHandlerInterceptor,org.springframework.mobile.device.DeviceHandlerMethodArgumentResolver (OnClassCondition)

   MongoAutoConfiguration
      - required @ConditionalOnClass classes not found: com.mongodb.Mongo (OnClassCondition)

   HibernateJpaAutoConfiguration
      - did not find HibernateEntityManager class (HibernateJpaAutoConfiguration.HibernateEntityManagerCondition)

   ReactorAutoConfiguration
      - required @ConditionalOnClass classes not found: reactor.spring.context.config.EnableReactor (OnClassCondition)

   RedisAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.data.redis.connection.lettuce.LettuceConnection,org.springframework.data.redis.core.RedisOperations,com.lambdaworks.redis.RedisClient (OnClassCondition)

   SecurityAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.security.authentication.AuthenticationManager (OnClassCondition)

   ThymeleafAutoConfiguration
      - required @ConditionalOnClass classes not found: org.thymeleaf.spring4.SpringTemplateEngine (OnClassCondition)

   EmbeddedServletContainerAutoConfiguration.EmbeddedJetty
      - required @ConditionalOnClass classes not found: org.eclipse.jetty.server.Server,org.eclipse.jetty.util.Loader (OnClassCondition)

   WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#beanNameViewResolver
      - @ConditionalOnBean (types: org.springframework.web.servlet.View; SearchStrategy: all) found no beans (OnBeanCondition)

   WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#viewResolver
      - @ConditionalOnBean (types: org.springframework.web.servlet.View; SearchStrategy: all) found no beans (OnBeanCondition)

   WebSocketAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.web.socket.WebSocketHandler (OnClassCondition)



2014-03-28 14:41:04.821  INFO 2852 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port: 9090
2014-03-28 14:41:04.829  INFO 2852 --- [           main] c.PiranhaStorageServiceClientApplication : Started PiranhaStorageServiceClientApplication in 4.231 seconds (JVM running for 5.249)
解决方案

I figured out that there is an issue with the MultipartAutoConfiguration within spring boot. I disabled it and added @Bean in the web config and it worked. Based on the exception I saw that the Jackson Mapper was trying to resolve the multipart content instead of the multipart resolver itself.

Here is the snippet.

@EnableAutoConfiguration(exclude={MultipartAutoConfiguration.class}

Add the following in your webconfig class

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

@Bean(name = "multipartResolver")
public CommonsMultipartResolver multipartResolver() {
    logger.info("Loading the multipart resolver");
    CommonsMultipartResolver multipartResolver
            = new CommonsMultipartResolver();
    return multipartResolver;
}

这篇关于所需的MultipartFile参数“文件”不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 20:01