嵌入式Tomcat容器的参数(maxParameterCount)设定
背景
昨天同事遇到了error一起看了一下感觉比较重要在这记录一下
基本情况是页面上选中9K+的数据向后台发送请求,然后系统就崩了。。。
error信息如下
More than the maximum number of request parameters (GET plus POST) for a single request ([10,000]) were detected.
Any parameters beyond this limit have been ignored. To change this limit, set the maxParameterCount attribute on the Connector.
简说 单次请求的参数超出限制,通过maxParameterCount来更改容器的限制。
经验里对于tomcat容器的设定最对就是端口号,超时,最大线程的设置比较多
这个【maxParameterCount 】的设定还没有过然后到网上去翻了翻,
在官网的文档(tomcat doc)里找到了如下
maxParameterCount |
The maximum number of parameter and value pairs (GET plus POST) which will be automatically parsed by the container. Parameter and value pairs beyond this limit will be ignored. A value of less than 0 means no limit. If not specified, a default of 10000 is used. Note that FailedRequestFilter filter can be used to reject requests that hit the limit. |
|
The maximum size in bytes of the POST which will be handled by the container FORM URL parameter parsing. The limit can be disabled by setting this attribute to a value less than zero. If not specified, this attribute is set to 2097152 (2 megabytes). Note that the FailedRequestFilter can be used to reject requests that exceed this limit. |
简说
maxParameterCount 是
tomcat容器来限定你 单次请求的参数的最大数量,默认是10000。所以通过这个属性你可以根据情况给设定适当的值。当然也有超出1w的情况怎么办?
上面文档里也有给出答案 小于0的设定可以禁用此制限。这也是很多网上资料设置-1的原因。
maxPostSize 是http-post单次请求内容或者说数据的最大限制,默认值为2M。同样小于0的设定可以禁用此制限
具体使用
tomcat/conf/server.xml文件中找到如下节点
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
(这里有好几个connector看自己用的是哪个端口的)
修改后
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" maxPostSize="-1" maxParameterCount="-1"/>
这是通常的做法,但有时如果tomcat容器内置的话你可能都找不到server.xml文件,
比如spring boo项目内置tomcat
这时候通常会想到 可以配置在application.properties里
然后翻一下看看application.properties里怎么配置
从spring-boot的doc看到只看到如下
server.tomcat.max-http-post-size=0 # Maximum size in bytes of the HTTP post content. |
并没有找到关于maxParameterCount信息,猜测不支持在配置文件里配置
继续翻
找到可以写在java类里的方法
@Bean
public EmbeddedServletContainerFactory mbeddedServletContainerFactory() {
TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = new TomcatEmbeddedServletContainerFactory(); tomcatEmbeddedServletContainerFactory.addConnectorCustomizers(connector ->{
connector.setMaxPostSize(2);
System.out.println("connector.getMaxPostSize: "+connector.getMaxPostSize());
System.out.println("connector.getPort: "+connector.getPort());
}); return tomcatEmbeddedServletContainerFactory;
}
代码本身并不多,过程比较曲折,大概说一下
EmbeddedServletContainerCustomizer
这是一个自定义内置容器的接口,通过实现它可以创建内置容器
然后还找到已经实现了它类,
AbstractEmbeddedServletContainerFactory,
JettyEmbeddedServletContainerFactory,
TomcatEmbeddedServletContainerFactory,
UndertowEmbeddedServletContainerFactory
这里看到了定制tomcat容器的工厂类
继续看看这个类里都什么可用(源码有点多就不贴了贴一张截图)
这里就是我们这次用到的函数了为什么标记两个因为上边那个也可用,下面是官网给的说明
当然其它的属性也可以在这里设定贴一下官网连接就不再代码体现了。
最新文章
- 优化php代码 - 字符串echo输出 逗号也可作php连接符
- ES6(二)解构赋值详解
- treeview所有节点递归解法(转+说明)或者说递归的实际应用
- 初识makefile
- 如何使用代码或脚本启用SharePoint的备用语言
- MySQL 视图的基础操作(五)
- js 字符串截取
- Resolving failed: Temporary failure in name resolution 错误解决方法
- Keil C51程序调试过程
- tl;drLegal ——开源软件license的搜索引擎
- jquery图片轮播代码
- 启动Tomcat自动加载(运行)类
- crawler_基于块儿统计正文抽取_改进版
- OpenStack/devstack with Neutron on Ubuntu 14 (1)
- Android滑动控件.md
- 合批只是对CPU的优化,与GPU没有任何关系
- 说说Java 位运算
- jenkins1
- 快排法求第k大
- Java clone克隆方法 --深拷贝--浅拷贝 --原型模型
热门文章
- UVA - 10249 The Grand Dinner
- C - The C Answer (2nd Edition) - Exercise 1-7
- 看看android基础知识,谁帮我作答
- 为WebClient增加Cookie的支持
- 七、Spring Boot Servlet 使用
- MPSOC之1——overview、开发板、工具
- Android LayoutInflator 解析
- ArcGIS API for JavaScript 4.2学习笔记[6] goTo()地图动画
- HtmlTestRunner无法生成HTML报告问题
- WebDriver API 大全