因项目原因由springmvc框架切换为Springboot,原文件上传模块报转换异常,如下代码:
CommonsMultipartFile cf= (CommonsMultipartFile)file; 抛出FileNotFound异常
在property文件中加入相应配置也毫无作用。
解决办法如下:
在Application中加入以下代码
@Bean(name = "multipartResolver")
public MultipartResolver multipartResolver(){
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setDefaultEncoding("UTF-8");
resolver.setResolveLazily(true); //resolveLazily属性启用是为了推迟文件解析,以在在UploadAction中捕获文件大小异常
resolver.setMaxInMemorySize(CommonConstant.MAX_MEMORY);
resolver.setMaxUploadSize(CommonConstant.MAX_SIZE);//上传文件大小 5M 5*1024*1024
return resolver;
}
并且在类上加上配置@EnableAutoConfiguration(exclude = {MultipartAutoConfiguration.class})
以上