Tomcat上java.lang.IllegalStateException: Optional int parameter 'id' is not present

今日, 本人在tomcat+spring mvc平台的服务器上遇到java.lang.IllegalStateException: Optional int parameter 'id' is not present异常, 很是怪异, mvc方法里面的id为int型, 明明是有值的, 为什么说没有? 改为Integer也不行, mvc方法直接无响应!

然后, 在本地模拟改用例, 发现可以正常执行, 而另一个同事说要把超长的图片参数放到Mvc方法的最后就可以正常访问! 怪异!

后来经过多次试验, 发现是其他参数的长度很长很长,例如存放图片的base64, 可能会超出tomcat的默认的post最多长度(2M), 但是网上很多人说超长抛出的异常应该是"post too large", 但是却抛出了另一种异常: :java.lang.IllegalStateException: Optional int parameter 'id' is not prese nt but cannot be translated into a null value due to being declared as a primiti ve type. Consider declaring it as object wrapper for the corresponding primitive  type.

本人的理解是sping mvc忽略了post too large异常, 直接对请求参数内容进行截取, 导致了id参数为空, 因此才出现了这样怪异的现象. 

解决的办法当然就是在tomcat的server.xml里面加一个maxPostSize="0"

原文地址:https://www.cnblogs.com/plain-heart/p/5362965.html