File tree Expand file tree Collapse file tree 5 files changed +95
-0
lines changed
java/com/back/global/config Expand file tree Collapse file tree 5 files changed +95
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,13 @@ dependencies {
6363 testImplementation(" org.springframework.boot:spring-boot-starter-test" )
6464 testImplementation(" org.springframework.security:spring-security-test" )
6565 testRuntimeOnly(" org.junit.platform:junit-platform-launcher" )
66+
67+ // Redis
68+ implementation(" org.springframework.boot:spring-boot-starter-data-redis" )
69+ implementation(" it.ozimov:embedded-redis:0.7.3" ) {
70+ exclude(group = " org.slf4j" , module = " slf4j-simple" )
71+ }
72+
6673}
6774
6875tasks.withType<Test > {
Original file line number Diff line number Diff line change 1+ package com .back .global .config ;
2+
3+ import jakarta .annotation .PostConstruct ;
4+ import jakarta .annotation .PreDestroy ;
5+ import org .springframework .context .annotation .Configuration ;
6+ import org .springframework .context .annotation .Profile ;
7+ import redis .embedded .RedisServer ;
8+ import redis .embedded .RedisServerBuilder ;
9+
10+ import java .io .IOException ;
11+
12+ /**
13+ * Embedded Redis 설정 클래스
14+ * - 개발 및 테스트 환경에서만 활성화 (dev, test 프로파일)
15+ * - 애플리케이션 시작 시 내장 Redis 서버 시작
16+ * - 애플리케이션 종료 시 내장 Redis 서버 중지
17+ */
18+ @ Configuration
19+ @ Profile ({"dev" , "test" })
20+ public class EmbeddedRedisConfig {
21+
22+ private RedisServer redisServer ;
23+
24+ public EmbeddedRedisConfig () throws IOException {
25+ this .redisServer = new RedisServerBuilder ()
26+ .port (6379 )
27+ .setting ("maxheap 256M" )
28+ .build ();
29+ }
30+
31+ @ PostConstruct
32+ public void startRedis () {
33+ redisServer .start ();
34+ }
35+
36+ @ PreDestroy
37+ public void stopRedis () {
38+ if (redisServer != null ) {
39+ redisServer .stop ();
40+ }
41+ }
42+ }
Original file line number Diff line number Diff line change 1+ package com .back .global .config ;
2+
3+ import org .springframework .context .annotation .Bean ;
4+ import org .springframework .context .annotation .Configuration ;
5+ import org .springframework .data .redis .connection .RedisConnectionFactory ;
6+ import org .springframework .data .redis .core .RedisTemplate ;
7+ import org .springframework .data .redis .serializer .Jackson2JsonRedisSerializer ;
8+ import org .springframework .data .redis .serializer .StringRedisSerializer ;
9+
10+ /**
11+ * Redis 설정 클래스
12+ */
13+ @ Configuration
14+ public class RedisConfig {
15+
16+ /**
17+ * RedisTemplate 설정
18+ * - Key: String
19+ * - Value: JSON (Jackson)
20+ */
21+ @ Bean
22+ public RedisTemplate <String , Object > redisTemplate (RedisConnectionFactory connectionFactory ) {
23+ RedisTemplate <String , Object > template = new RedisTemplate <>();
24+ template .setConnectionFactory (connectionFactory );
25+
26+ // Key: String
27+ template .setKeySerializer (new StringRedisSerializer ());
28+ template .setHashKeySerializer (new StringRedisSerializer ());
29+
30+ // Value: JSON
31+ template .setValueSerializer (new Jackson2JsonRedisSerializer <>(Object .class ));
32+ template .setHashValueSerializer (new Jackson2JsonRedisSerializer <>(Object .class ));
33+
34+ return template ;
35+ }
36+ }
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+
813 config :
914 import : optional:file:.env[.properties]
1015
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+
813jwt :
914 secret : test-jwt-secret-key-12345678901234567890
1015 access-token-expiration : ${JWT_ACCESS_TOKEN_EXPIRATION:1800} # 30분 (초 단위)
You can’t perform that action at this time.
0 commit comments