본문 바로가기
웹개발지식쌓기

[back] List<Class> 256개 초과 시 저장되지 않는 오류

by developer_j 2024. 7. 22.
728x90
반응형

다른 분들은 index 오류가 뜨던데 나는 오류 로그도 따로 안뜨는데 저장이 안되길래 몇시간동안 확인해보니 이 오류였다.

저장 시 하위 상품을 같이 저장하는데, 하위 상품이 희한하게 256개만 초과되면 아무 반응이 없고 저장이 안됐다. 뭔가 익숙한 숫자.. 256..

 

구글링 결과,

1. 톰캣 설정에서 maxParameterCount 값을 -1(무제한)로 설정하거나

2. @initBinder 어노테이션을 Controller 안에 설정해주면 된다

 


 

1. maxParameterCount 값 수정

server.xml

<Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443"
               URIEncoding="UTF-8"
               maxParameterCount="-1"/> <!-- maxParameterCount 수정 -->

 

maxParameterCount 값을 따로 설정한 적은 없었는데,

출처 에 따르면 maxParameterCount 값은 defualt가 10000개이며, post로 전송 시 2MB가 전송크기 제한이라고 되어 있다고 하는데

https://youngram2.tistory.com/110

 

tomcat maxPostsize, maxParameterCount 설정

Tomcat MaxPostSize 개발을 하다보면 흔히 격지는 않지만, 나의 경우에는 지금과 같은 게시판 형태의 글이었는데, 엄청나게 많은 컨텐츠를submit을 했더니, 무슨 영문인지는 모르겠지만 처리가 안되고

youngram2.tistory.com

 

내가 보내려는 데이터는 300개 이하였으며, 크기도 13KB 정도로 2MB에 택도 없었지만 오류가 발생했다.

그래서 위의 값을 수정하지는 않았고 아래의 2번 방법을 선택했다.

 

 

2. @initBinder 어노테이션 추가

늘려야 할 List를 사용하는 소스파일 상단에 @initBinder 어노테이션을 작성해준다.

	@InitBinder
	protected void initBinder(WebDataBinder binder) {
		binder.setAutoGrowNestedPaths(true);
		binder.setAutoGrowCollectionLimit(1024);
	}

 

①.setAutoGrowNestedPaths(true)

→ 이 함수 호출을 통해 초기화한다.

초기화해주지 않으면 "DataBinder is already initialized - call setAutoGrowNestedPaths before other configuration methods" 이 오류를 만난다고 한다.
그런데 spring 기본문서를 보면 defualt 값이 true이기때문에, 위 오류가 발생하면 이 함수의 값을 true로 세팅해주도록 하면 될 것 같다.

 

②.setAutoGrowCollectionLimit(1024);

이 함수 호출을 통해 Limit 갯수를 늘려준다. 1024 대신 본인이 필요한 만큼 숫자 작성

 

 


참고자료

https://javafactory.tistory.com/1323

 

Spring MVC Error : Index of out of bounds in property path 'pahtname[256]' 오류 잡기

오류 메세지 : Invalid property 'metaDatas[256]' of bean class[com.comas.solme.ecm.admin.cm.action.ContentsModel]: Index of out of bounds in property path 'metaDatas[256]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256

javafactory.tistory.com

 

https://itstart-190126.tistory.com/entry/SPRING-request-parameter-binding%EC%8B%9C-%EC%98%A4%EB%A5%98-List-Size-256

 

[SPRING] request parameter binding시 오류 - List Size 256

Spring boot project 하는데 List로 Parameter를 넘겼는데 List.Size가 256을 초과한다는 에러가 났다. org.springframework.beans.InvalidPropertyException Exception = org.springframework.beans.InvalidPropertyException: Invalid property 'lists

itstart-190126.tistory.com

 

https://pshcode.tistory.com/30

 

스프링 동적리스트 바인딩시 256개 초과하여 IndexOutOfBoundsException오류 해결

스프링 동적리스트 바인딩의 경우 최대 256개까지가 기본설정으로 되어 있다.만약, 256개 이상을 파라미터로 넘기게 된다면 IndexOutOfBoundsException이 발생하게 될 것이다. 해결방법은 스프링 InitBinder

pshcode.tistory.com

 

728x90
반응형