본문 바로가기
how to

how to set Session clustering in springboot

by 즉흥 2025. 5. 20.
728x90
반응형

스프링부트(sprintboot) 환경에서 세션 클러스터링 적용시 유의해야할 부분

 

1. (tomcat) /conf/server.xml 설정

<Cluster> 설정과 그 안의 <Membership> 설정시 포트 충돌 유의

 

2. (tomcat) /conf/context.xml 설정

두 서버간 sessionCookieName 설정을 동일하게 할 것

WatchedResource에 web.xml 명시

 

3. web.xml

<distributable /> 태그 추가

*정 안 되면 war 파일 내에 아래 내용으로 /WEB-INF/web.xml을 추가

<web-app version="3.0">
    <distributable />
</web-app>

 

4. logging.properties 내용 추가

아래 세 줄을 추가하면 두 was 간 공유되는 세션 내용을 상세히 알 수 있음

org.apache.catalina.ha.session.DeltaManager.level = FINEST
org.apache.catalina.ha.tcp.SimpleTcpCluster.level = FINEST
org.apache.catalina.tribes.level = FINEST

 

5. 모든 세션 데이터에 직렬화(serialize) 적용

세션에 들어가는 모든 데이터를 직렬화 해야 한다.

 

그렇지 않은 경우에는 catalina.out에서 "setAttribute: Non-serializable attribute [변수명]" 이런 메시지를 확인 할 수 있음

 

ex.

import java.io.serialize

public class sessionDATA implement Serializable

 

6. pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

 

spring-boot-starter-tomcat 이 있다면 <scope> provided </scope> 추가

 

빌드할 때는 해당 디팬던시를 사용하지만, 실제로는 사용하지 않겠다는 뜻

 

별도의 외부 tomcat이 있는 이중화 환경에서 springboot의 내장 tomcat을 사용하지 않는다는 의미다.

728x90
반응형

댓글