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**);
}

你可能感兴趣的:(Java,ArrayList,Spring,java,spring,boot,list)