IndexOutOfBoundsException: Index: 2048, Size: 2048] Controller接收对象集合长度超过2048错误

完整异常信息:

复制代码
org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [spring] in context with path [/jsgc] threw exception [Request processing failed; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'tpbidresults[2048]' of bean class [cn.pinming.notice.entity.TPNotice]: Index of out of bounds in property path 'tpbidresults[2048]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 2048, Size: 2048] with root cause
	java.lang.IndexOutOfBoundsException: Index: 2048, Size: 2048
		at java.util.ArrayList.rangeCheck(ArrayList.java:657)
		at java.util.ArrayList.get(ArrayList.java:433)
		at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:652)
		at org.springframework.beans.AbstractNestablePropertyAccessor.getNestedPropertyAccessor(AbstractNestablePropertyAccessor.java:836)
		at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyAccessorForPropertyPath(AbstractNestablePropertyAccessor.java:813)
		at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:270)
		at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95)
		at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:834)
		at org.springframework.validation.DataBinder.doBind(DataBinder.java:730)
		at org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:189)
		at org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:106)
		at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.bindRequestParameters(ServletModelAttributeMethodProcessor.java:150)
		at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:110)
		at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:99)
		at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161)
		at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128)
		at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
		at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:817)
		at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:731)
		at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
		at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
		at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
		at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)
		at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:870)
		at javax.servlet.http.HttpServlet.service(HttpServlet.java:682)
		at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844)
		at javax.servlet.http.HttpServlet.service(HttpServlet.java:765)
		at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)

原因解释:

Spring接受前台的数据超过2048出现如下异常:前台的Form 元素绑定到 后台的JaveBean对象,做的一个映射,但是这个映射的List长度不可以超过2048

溯源了下Spring的代码,找到了DataBinder,先解释下DataBinder类的作用,见链接

链接: http://docs.spring.io/spring/docs/1.2.x/api/org/springframework/validation/DataBinder.html

可以在controller 规定 长度即可;

解决方案:

复制代码
@InitBinder
public void initBinder(WebDataBinder binder) {

    binder.setAutoGrowCollectionLimit(**2048**);
}
相关推荐
Code blocks32 分钟前
关于“LoggerFactory is not a Logback LoggerContext but Logback is on ......“的解决方案
java·spring boot·后端
飞翔的佩奇1 小时前
基于SpringBoot+MyBatis+MySQL+VUE实现的经方药食两用服务平台管理系统(附源码+数据库+毕业论文+部署教程+配套软件)
数据库·vue.js·spring boot·mysql·毕业设计·mybatis·经方药食两用平台
04Koi.3 小时前
八股训练--Spring
java·后端·spring
Dcs4 小时前
微软 Copilot 被“越狱”?安全研究员教你一招拿下“沙箱环境 Root 权限”!
java
℡余晖^4 小时前
每日面试题18:基本数据类型和引用数据类型的区别
java
纯洁的小魔鬼4 小时前
Springboot 配置 doris 连接
spring boot·doris·连接池
c_zyer4 小时前
Mermaid流程图可视化系统:基于Spring Boot与Node.js的三层架构实现
spring boot·node.js·流程图·mermaid
hello 早上好4 小时前
消息顺序、消息重复问题
java·中间件
phltxy5 小时前
ArrayList与顺序表
java·算法
Doris_LMS5 小时前
保姆级别IDEA关联数据库方式、在IDEA中进行数据库的可视化操作(包含图解过程)
java·mysql·postgresql