본문 바로가기
🛠 백엔드/🤬오류 삽질 로그

_csrf.token parsingError

by meteorfish 2023. 1. 18.
728x90

https://stackoverflow.com/a/53004917/5366876

 

Spring/Thymeleaf throws "Cannot create a session after the response has been committed" when processing @PostMapping

I build a Spring MVC application with thymeleaf views and ran into the following problem. I have a page which should process a form and create a new Entity to persist in the database. In my control...

stackoverflow.com

로그

Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "_csrf.token" (template: "member/memberForm" - line 52, col 63)

Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "_csrf.token" (template: "member/memberForm" - line 52, col 63)

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1021E: A problem occurred whilst attempting to access the property 'token': 'Unable to access property 'token' through getter method'

Caused by: org.springframework.expression.AccessException: Unable to access property 'token' through getter method

Caused by: java.lang.reflect.InvocationTargetException: null

Caused by: java.lang.IllegalStateException: Cannot create a session after the response has been committed

 

응답 커밋 후, 세션을 만들지 못해서 발생해서 발생한 오류

 

그래서 세션 정책을 ALL로 변경하였다.

 

[출처] https://fenderist.tistory.com/342

http

      .sessionManagement()

      .sessionCreationPolicy( SessionCreationPolicy.정책상수)

 

      SessionCreationPolicy.ALWAYS        - 스프링시큐리티가 항상 세션을 생성

      SessionCreationPolicy.IF_REQUIRED - 스프링시큐리티가 필요시 생성(기본) 

      SessionCreationPolicy.NEVER           - 스프링시큐리티가 생성하지않지만, 기존에 존재하면 사용

      SessionCreationPolicy.STATELESS     - 스프링시큐리티가 생성하지도않고 기존것을 사용하지도 않음

 

728x90