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>
提出以下例外:
[错误] 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
{
我添加此配置并正确工作。
@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;
}
和跳过多Artartautoconfiguration.Class:
@SpringBootApplication(exclude = { MultipartAutoConfiguration.class })