본문 바로가기

팁???

참조 에러

' java.lang.IllegalStateException: Cannot call sendError() after the response has been committed '

2021-06-15 15:33:24.943 ERROR 17900 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: com.jpacrud.domain.Member["team"]->com.jpacrud.domain.Team["members"]->org.hibernate.collection.internal.PersistentBag[0]->com.jpacrud.domain.Member["team"]->com.jpacrud.domain.Team["members"]->org.hibernate.collection.internal.PersistentBag[0]->com.jpacrud.domain.Member["team"]->com.jpacrud.domain.Team["members"]->org.hibernate.collection.internal.PersistentBag[0]- with root cause

java.lang.StackOverflowError: null

 

위와 같은 에러발생시

  1. @JsonManagedReference, @JsonBackReference 추가

@JsonManagedReference

양방향 관계에서 정방향(자식->부모) 참조할 변수에 어노테이션을 추가하면 직렬화에 포함된다

@JsonBackReference

양방향 관계에서 역방향(부모->자식) 참조로 어노테이션을 추가하면 직렬화에서 제외된다