jwt 방식 로그인을 사용하기 때문에 세션을 생성하지 않도록 Spring Security 에서 아래와 같이 설정했다.
근데도 JSESSIONID가 생기고 있었다. 나는 jsp를 사용하는게 문제였다!!
📌 1. 목적: 완전한 무상태(Stateless) 서버 만들기
- Spring Security에서 SessionCreationPolicy.STATELESS를 설정
- JWT 기반 인증이나 토큰 기반 인증을 쓸 때는 세션이 필요 없으므로, JSESSIONID 쿠키도 없어야 정상.
http
.cors(Customizer.withDefaults())
.csrf(csrf -> csrf.disable())
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
)
📌 2. SESSIONID가 생기는 이유
✅ 2-1. Spring MVC 코드에서 세션 생성
- request.getSession() 또는 request.getSession(true) 호출 시, 세션이 무조건 생성됨
- request.getSession(false); 을 사용해야한다.
request.getSession(); // 세션 생성됨
request.getSession(true); // 세션 생성됨
request.getSession(false); // 세션 없으면 null
✅ 2-2. JSP가 자동으로 세션 생성
- JSP 기본 설정은 <%@ page session="true" %> 이므로, JSP가 호출되면 세션 자동 생성됨
-
<%@ page session="false" %>
'Backend > spring (Boot)' 카테고리의 다른 글
| Connection Pool과 Size 선정 기준 (with HikariCP) (0) | 2025.09.01 |
|---|---|
| [Spring] (프로젝트 외부) 정적 리소스 처리 (0) | 2025.07.26 |
| Spring boot 예외 처리: @ControllerAdvice, @ExceptionHandler, ResponseStatusException (0) | 2025.07.26 |
| [error] java.lang.IllegalArgumentException: Name for argument of type [int] not specified (0) | 2025.02.23 |
| [error] getOutputStream() has already been called for this response (0) | 2025.02.23 |