背景:springboot项目上传图片超过1M报错,经了解,springboot默认上传文件1M
需求:更改默认配置,控制上传文件大小
方法:①更改配置文件(经试验不可行,不知道为什么);②更改启动Bean(药到病除)
一、springboot版本
二、配置文件解决
三、更改启动Bean
@Bean public MultipartConfigElement multipartConfigElement() { MultipartConfigFactory factory = new MultipartConfigFactory(); //单个文件最大 factory.setMaxFileSize("10MB"); /// 设置总上传数据总大小 factory.setMaxRequestSize("50MB"); return factory.createMultipartConfig(); }