File tree Expand file tree Collapse file tree 2 files changed +20
-12
lines changed
java/com/back/global/config Expand file tree Collapse file tree 2 files changed +20
-12
lines changed Original file line number Diff line number Diff line change 88import redis .embedded .RedisServerBuilder ;
99
1010import java .io .IOException ;
11+ import java .net .ServerSocket ;
1112
1213/**
1314 * Embedded Redis 설정 클래스
2021public class EmbeddedRedisConfig {
2122
2223 private RedisServer redisServer ;
24+ private int port ;
2325
24- public EmbeddedRedisConfig () throws IOException {
25- this .redisServer = new RedisServerBuilder ()
26- .port (6379 )
26+ @ PostConstruct
27+ public void startRedis () throws IOException {
28+ port = findAvailablePort ();
29+ redisServer = new RedisServerBuilder ()
30+ .port (port )
2731 .setting ("maxheap 256M" )
2832 .build ();
29- }
30-
31- @ PostConstruct
32- public void startRedis () {
3333 redisServer .start ();
34+
35+ // 동적으로 찾은 포트를 Spring 환경 변수에 반영
36+ System .setProperty ("spring.data.redis.port" , String .valueOf (port ));
3437 }
3538
3639 @ PreDestroy
@@ -39,4 +42,14 @@ public void stopRedis() {
3942 redisServer .stop ();
4043 }
4144 }
45+
46+ // 사용 가능한 포트를 찾는 유틸리티 메서드
47+ private int findAvailablePort () {
48+ try (ServerSocket socket = new ServerSocket (0 )) {
49+ socket .setReuseAddress (true );
50+ return socket .getLocalPort ();
51+ } catch (IOException e ) {
52+ throw new IllegalStateException ("No available port found" , e );
53+ }
54+ }
4255}
Original file line number Diff line number Diff line change 55 username : sa
66 password :
77
8- data :
9- redis :
10- host : localhost
11- port : 6379
12-
138jwt :
149 secret : test-jwt-secret-key-12345678901234567890
1510 access-token-expiration : ${JWT_ACCESS_TOKEN_EXPIRATION:1800} # 30분 (초 단위)
You can’t perform that action at this time.
0 commit comments