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**);
}
相关推荐
Daniel 大东10 分钟前
idea 解决缓存损坏问题
java·缓存·intellij-idea
2401_8576363911 分钟前
共享汽车管理新纪元:SpringBoot框架应用
数据库·spring boot·汽车
wind瑞16 分钟前
IntelliJ IDEA插件开发-代码补全插件入门开发
java·ide·intellij-idea
HappyAcmen16 分钟前
IDEA部署AI代写插件
java·人工智能·intellij-idea
马剑威(威哥爱编程)22 分钟前
读写锁分离设计模式详解
java·设计模式·java-ee
鸽鸽程序猿22 分钟前
【算法】【优选算法】前缀和(上)
java·算法·前缀和
修道-032323 分钟前
【JAVA】二、设计模式之策略模式
java·设计模式·策略模式
九圣残炎28 分钟前
【从零开始的LeetCode-算法】2559. 统计范围内的元音字符串数
java·算法·leetcode
当归102441 分钟前
若依项目-结构解读
java
man201743 分钟前
【2024最新】基于springboot+vue的闲一品交易平台lw+ppt
vue.js·spring boot·后端