org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request

问题:

在上传附件的时候,报错:

org.springframework.web.multipart.MultipartException: 
Failed to parse multipart servlet request;
nested exception is java.lang.IllegalStateException: 
The multi-part request contained parameter data (excluding uploaded files) 
that exceeded the limit for maxPostSize set on the associated connector

是上传文件的大小超出了最大值。

处理:

检查了下yml的配置:

spring: 
  servlet:
    multipart:
      max-file-size: 100MB
      max-request-size: 100MB

这个没有问题。

再检查 server的配置:

server:
    servlet:
        context-path: /api/v1

这边没有设置 tomcat.max-http-form-post-size 的值

默认是2M,这个值不够,改为100M

server:
    servlet:
        context-path: /api/v1
    tomcat:
      max-http-post-size: 100M

重启服务后,再重启。上传正常了。 

总结:

 错误中that exceeded the limit for maxPostSize  可以看出是请求post的大小值超出了,要在server里面的tomcat里的max-http-post-size修改其大小值就行。

猜你喜欢

转载自blog.csdn.net/qq_35461948/article/details/130130595