spring.servlet.multipart配置不生效问题
spring.servlet.multipart.enabled 是否为 true。比如springboot 2.X 以上版本,则进行如下配置。MultipartProperties 属性类。使用的是tomcat作为web容器。spring 启用配置开关。
·
1、如果接口请求报错是nginx引起的
检查下nginx中的配置:
http {
client_max_body_size 100m;
}
或:
location ^~ /aaa/ {
client_max_body_size 100m;
client_body_buffer_size 128k;
}
2、如果是接口引起
使用的是tomcat作为web容器
比如springboot 2.X 以上版本,则进行如下配置
spring:
servlet:
multipart:
# 开启配置
enabled: true
# 上传文件大小限制
max-request-size: 100MB
max-file-size: 100MB
3、为什么这么配置,原因如下
MultipartProperties 属性类
@ConfigurationProperties(prefix = "spring.servlet.multipart", ignoreUnknownFields = false)
public class MultipartProperties {
spring 启用配置开关
spring.servlet.multipart.enabled 是否为 true
MultipartAutoConfiguration
@AutoConfiguration
@ConditionalOnClass({ Servlet.class, StandardServletMultipartResolver.class, MultipartConfigElement.class })
@ConditionalOnProperty(prefix = "spring.servlet.multipart", name = "enabled", matchIfMissing = true)
@ConditionalOnWebApplication(type = Type.SERVLET)
@EnableConfigurationProperties(MultipartProperties.class)
public class MultipartAutoConfiguration {
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)