Spring Boot配置内置Tomcat的maxPostSize值

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013810234/article/details/81136416

Background

前端页面表单输入数据较多,包含多个文本、多张图片,在数据未压缩的情况下,最终上传失败。

Problem 1

后端报错:

java.lang.IllegalStateException: The multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector

即:请求数据量过大,超出了最大阈值。

  • Solution:

修改Spring Boot内置Tomcat的maxPostsize值,在application.yml配置文件中添加以下内容:

server:  
  tomcat:
    max-http-post-size: -1

Note: 以下配置并不能解决Tomcat请求数据量的限制问题

spring:
  servlet:
    multipart:
      max-file-size: 30Mb
      max-request-size: 100Mb

Problem 2

解决了应用服务器请求数据量过大问题后,在下一步写入DB时又遇到了类似问题,超出了数据库中最大允许数据包默认配置值。

Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (16800061 > 16777216). You can change this value on the server by setting the max_allowed_packet’ variable.

  • Solution:

修改DB的max_allowed_packet值:

USE demo;
set global max_allowed_packet = 3*1024*1024*10; # 改为30M
show VARIABLES like '%max_allowed_packet%'; # 重启DB连接生效

Note:MySQLmax_allowed_packet 的 默认配置:16777216 = 16 * 1024 * 1024,即16M


If you have any questions or any bugs are found, please feel free to contact me.

扫描二维码关注公众号,回复: 5937970 查看本文章

Your comments and suggestions are welcome!

猜你喜欢

转载自blog.csdn.net/u013810234/article/details/81136416