CommonsMultipartResolver和春季会议相互干扰

时间:2017-09-12 08:57:01

标签: spring-boot multipart spring-session

在spring boot中有多部分配置的配置

@Bean
public CommonsMultipartResolver multipartResolver() {
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setDefaultEncoding("utf-8");
resolver.setMaxInMemorySize(20480);
resolver.setMaxUploadSize(2048000000);
return resolver;
}

当添加以下依赖项时,它是正确的并且成功地工作

           <dependency>
                <groupId>org.springframework.session</groupId>
                <artifactId>spring-session</artifactId>
            </dependency>

引发了以下异常:

  

[ERROR]   org.springframework.web.multipart.support.MissingServletRequestPartException:   必需的请求部分'文件'不存在必需的请求部分   '文件'不存在

哪里错了?

编辑:

它是相关的控制器:

@RequestMapping(value={"/save"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
  @ResponseBody
  public FileProviderDto save(@RequestParam("file") MultipartFile file, @RequestParam String fileCode)
     throws IOException, SQLException
   {

1 个答案:

答案 0 :(得分:0)

我添加此配置并正常工作。

@Bean
public CommonsMultipartResolver multipartResolver() {
    CommonsMultipartResolver resolver = new CommonsMultipartResolver();
    resolver.setDefaultEncoding("utf-8");
    resolver.setMaxInMemorySize(20480);
    resolver.setMaxUploadSize(2048000000);
    return resolver;
}

@Bean
@Order(0)
public MultipartFilter multipartFilter() {
    MultipartFilter multipartFilter = new MultipartFilter();
    multipartFilter.setMultipartResolverBeanName("multipartResolver");
    return multipartFilter;
}

并跳过这样的MultipartAutoConfiguration.class:

@SpringBootApplication(exclude = { MultipartAutoConfiguration.class })