SpringBoot项目上使用富文本框,如果图片很多的话,会报如下错误:
2020-09-28 14:26:59.568 ERROR 8 --- [nio-8098-exec-5] Servlet.service() for servlet [dispatcherServlet] in context with path [/product-manage] threw exception [Request processing failed; nested exception is 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] with root cause
java.lang.IllegalStateException: The multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector
这个是字符串接收,不是文件接收,请求方式是post,post本身没有参数大小限制,但是tomcat给限制了,于是解决方式如下:
一、外置的tomcat
这个简单,直接在server.xml里面添加或者修改这句话:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="2000"
redirectPort="8443"
URIEncoding="UTF-8"
maxThreads="3000"
compression="on" compressableMimeType="text/html,text/xml"
maxPostSize="0"
/>
修改这里的maxPostSize的值,默认是1024,改成0,就可以不限制了大小了
二、使用spring boot自带的tomcat
那就在application.properties中加上这句话:
server.tomcat.max-http-post-size=0
如果是SpringBoot 2.x版本加这句话:
server.tomcat.max-http-post-size=-1
修改了配置之后记得重启服务器,做了热部署的伙伴,如果无效,记得重启一下再测试。