diff --git a/build.gradle b/build.gradle index 80dd076b..78822f0b 100644 --- a/build.gradle +++ b/build.gradle @@ -139,11 +139,9 @@ subprojects { implementation 'io.jsonwebtoken:jjwt-api:0.11.5' implementation 'com.google.firebase:firebase-admin:9.2.0' implementation 'com.google.api-client:google-api-client:1.32.1' - implementation 'org.springframework.boot:spring-boot-starter-data-redis' implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.3' implementation 'net.javacrumbs.shedlock:shedlock-spring:5.10.0' implementation 'net.javacrumbs.shedlock:shedlock-provider-jdbc-template:5.10.0' - implementation 'it.ozimov:embedded-redis:0.7.2' runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' implementation("com.nimbusds:nimbus-jose-jwt:9.37") diff --git a/gateway/src/main/java/com/oing/config/redis/EmbeddedRedisConfig.java b/gateway/src/main/java/com/oing/config/redis/EmbeddedRedisConfig.java deleted file mode 100644 index 716e8536..00000000 --- a/gateway/src/main/java/com/oing/config/redis/EmbeddedRedisConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.oing.config.redis; - -import jakarta.annotation.PostConstruct; -import jakarta.annotation.PreDestroy; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.data.redis.RedisConnectionFailureException; -import redis.embedded.RedisServer; - -import java.io.File; - -@Configuration -@Profile("local") -@Slf4j -public class EmbeddedRedisConfig { - - @Value("${spring.data.redis.port}") - private int port; - - private RedisServer redisServer; - - @PostConstruct - public void startRedis() { - try { - redisServer = RedisServer.builder() - .port(port) - .setting("maxmemory 256M") - .build(); - redisServer.start(); - - } catch (RuntimeException e) { // Run redis manually - redisServer = new RedisServer(new File("/usr/local/bin/redis-server"), port); - redisServer.start(); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @PreDestroy - public void stopRedis() { - redisServer.stop(); - } -} diff --git a/gateway/src/main/java/com/oing/config/redis/RedisCacheConfig.java b/gateway/src/main/java/com/oing/config/redis/RedisCacheConfig.java deleted file mode 100644 index 4afb89ce..00000000 --- a/gateway/src/main/java/com/oing/config/redis/RedisCacheConfig.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.oing.config.redis; - -import org.springframework.cache.CacheManager; -import org.springframework.cache.annotation.EnableCaching; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.data.redis.cache.RedisCacheConfiguration; -import org.springframework.data.redis.cache.RedisCacheManager; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; -import org.springframework.data.redis.serializer.RedisSerializationContext; -import org.springframework.data.redis.serializer.StringRedisSerializer; - -import java.time.Duration; - -@EnableCaching -@Configuration -public class RedisCacheConfig { - - @Bean - @Primary - public CacheManager monthlyCalendarCacheManager(RedisConnectionFactory redisConnectionFactory) { - RedisCacheConfiguration redisCacheConfiguration = generateCacheConfiguration() - .entryTtl(Duration.ofHours(5L)); - - return RedisCacheManager.RedisCacheManagerBuilder - .fromConnectionFactory(redisConnectionFactory) - .cacheDefaults(redisCacheConfiguration) - .build(); - } - - private RedisCacheConfiguration generateCacheConfiguration() { - return RedisCacheConfiguration.defaultCacheConfig() - .serializeKeysWith( - RedisSerializationContext.SerializationPair.fromSerializer( - new StringRedisSerializer())) - .serializeValuesWith( - RedisSerializationContext.SerializationPair.fromSerializer( - new GenericJackson2JsonRedisSerializer())); - } -} diff --git a/gateway/src/main/java/com/oing/config/redis/RedisConfig.java b/gateway/src/main/java/com/oing/config/redis/RedisConfig.java deleted file mode 100644 index 6f78f0ad..00000000 --- a/gateway/src/main/java/com/oing/config/redis/RedisConfig.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.oing.config.redis; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.data.redis.connection.RedisClusterConfiguration; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration; -import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; -import org.springframework.data.redis.serializer.StringRedisSerializer; - -import java.util.Collections; - -@Profile({"prod", "dev"}) -@Configuration -public class RedisConfig { - - @Value("${spring.data.redis.host}") - private String redisHost; - - @Value("${spring.data.redis.port}") - private int redisPort; - - @Bean - public RedisConnectionFactory redisConnectionFactory() { - LettuceClientConfiguration configuration = LettuceClientConfiguration.builder().useSsl().build(); - return new LettuceConnectionFactory(new RedisClusterConfiguration(Collections.singleton(redisHost + ":" + redisPort)), configuration); - } - - @Bean - public RedisTemplate redisTemplate() { - RedisTemplate redisTemplate = new RedisTemplate<>(); - redisTemplate.setConnectionFactory(redisConnectionFactory()); - redisTemplate.setKeySerializer(new StringRedisSerializer()); - - /* Java 기본 직렬화가 아닌 JSON 직렬화 설정 */ - redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); - - return redisTemplate; - } -} diff --git a/gateway/src/main/java/com/oing/config/redis/RedisLocalConfig.java b/gateway/src/main/java/com/oing/config/redis/RedisLocalConfig.java deleted file mode 100644 index adae4cbf..00000000 --- a/gateway/src/main/java/com/oing/config/redis/RedisLocalConfig.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.oing.config.redis; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.connection.RedisStandaloneConfiguration; -import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; -import org.springframework.data.redis.serializer.StringRedisSerializer; - -@Profile("local") -@Configuration -public class RedisLocalConfig { - - @Value("${spring.data.redis.host}") - private String redisHost; - - @Value("${spring.data.redis.port}") - private int redisPort; - - @Bean - public RedisConnectionFactory redisConnectionFactory() { - return new LettuceConnectionFactory(new RedisStandaloneConfiguration(redisHost, redisPort)); - } - - @Bean - public RedisTemplate redisTemplate() { - RedisTemplate redisTemplate = new RedisTemplate<>(); - redisTemplate.setConnectionFactory(redisConnectionFactory()); - redisTemplate.setKeySerializer(new StringRedisSerializer()); - - /* Java 기본 직렬화가 아닌 JSON 직렬화 설정 */ - redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); - - return redisTemplate; - } -} diff --git a/gateway/src/main/java/com/oing/controller/CalendarController.java b/gateway/src/main/java/com/oing/controller/CalendarController.java index cdbe1f06..4953e5c9 100644 --- a/gateway/src/main/java/com/oing/controller/CalendarController.java +++ b/gateway/src/main/java/com/oing/controller/CalendarController.java @@ -12,7 +12,6 @@ import com.oing.service.PostService; import com.oing.util.OptimizedImageUrlGenerator; import lombok.RequiredArgsConstructor; -import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Controller; import java.time.LocalDate; @@ -32,7 +31,6 @@ public class CalendarController implements CalendarApi { @Override - @Cacheable(value = "calendarCache", key = "#familyId.concat(':').concat(#yearMonth)", cacheManager = "monthlyCalendarCacheManager") public ArrayResponse getMonthlyCalendar(String yearMonth, String familyId) { if (yearMonth == null) yearMonth = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM")); diff --git a/gateway/src/main/resources/application-dev.yaml b/gateway/src/main/resources/application-dev.yaml index af7874fe..3976248f 100644 --- a/gateway/src/main/resources/application-dev.yaml +++ b/gateway/src/main/resources/application-dev.yaml @@ -30,10 +30,6 @@ spring: h2: console: enabled: false - data: - redis: - host: ${REDIS_HOST} - port: ${REDIS_PORT} management: endpoints: diff --git a/gateway/src/main/resources/application-prod.yaml b/gateway/src/main/resources/application-prod.yaml index bfe68fae..06e78c80 100644 --- a/gateway/src/main/resources/application-prod.yaml +++ b/gateway/src/main/resources/application-prod.yaml @@ -29,10 +29,6 @@ spring: h2: console: enabled: false - data: - redis: - host: ${REDIS_HOST} - port: ${REDIS_PORT} logging: pattern: diff --git a/gateway/src/main/resources/application-test.yaml b/gateway/src/main/resources/application-test.yaml index a17b792e..c7af66a6 100644 --- a/gateway/src/main/resources/application-test.yaml +++ b/gateway/src/main/resources/application-test.yaml @@ -16,12 +16,6 @@ spring: format_sql: false dialect: org.hibernate.dialect.MySQL8Dialect database-platform: org.hibernate.dialect.MySQL8Dialect - data: - redis: - host: localhost - port: 16379 - ssl: - enabled: true app: external-urls: diff --git a/gateway/src/main/resources/application.yaml b/gateway/src/main/resources/application.yaml index 1c43672f..333f0167 100644 --- a/gateway/src/main/resources/application.yaml +++ b/gateway/src/main/resources/application.yaml @@ -20,15 +20,6 @@ spring: enabled: true settings: web-allow-others: true - data: - redis: - host: ${REDIS_HOST} - port: ${REDIS_PORT} - lettuce: - pool: - max-active: 16 - min-idle: 8 - max-idle: 10 app: oauth: diff --git a/gateway/src/main/resources/template-application-local.yaml b/gateway/src/main/resources/template-application-local.yaml index 1fb634ff..ae900e46 100644 --- a/gateway/src/main/resources/template-application-local.yaml +++ b/gateway/src/main/resources/template-application-local.yaml @@ -12,10 +12,6 @@ spring: enabled: true show_sql: true format_sql: true - data: - redis: - host: ${REDIS_HOST} # Must Be Replaced - port: ${REDIS_PORT} # Must Be Replaced app: oauth: diff --git a/gateway/src/test/java/com/oing/restapi/CalendarApiTest.java b/gateway/src/test/java/com/oing/restapi/CalendarApiTest.java index 71236185..52d67c4b 100644 --- a/gateway/src/test/java/com/oing/restapi/CalendarApiTest.java +++ b/gateway/src/test/java/com/oing/restapi/CalendarApiTest.java @@ -8,8 +8,6 @@ import com.oing.dto.response.DeepLinkResponse; import com.oing.dto.response.FamilyResponse; import com.oing.service.*; -import com.oing.support.EmbeddedRedisConfig; -import com.oing.support.RedisTestConfig; import jakarta.persistence.EntityManager; import jakarta.transaction.Transactional; import org.junit.jupiter.api.BeforeEach; @@ -18,8 +16,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Import; -import org.springframework.data.redis.core.RedisTemplate; import org.springframework.http.MediaType; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; @@ -34,7 +30,6 @@ @SpringBootTest -@Import({EmbeddedRedisConfig.class, RedisTestConfig.class}) @ActiveProfiles("test") @Transactional @AutoConfigureMockMvc @@ -59,8 +54,6 @@ class CalendarApiTest { private DeepLinkService deepLinkService; @Autowired private TokenGenerator tokenGenerator; - @Autowired - private RedisTemplate redisTemplate; private String TEST_MEMBER1_ID; private String TEST_MEMBER1_TOKEN; diff --git a/gateway/src/test/java/com/oing/restapi/PostApiTest.java b/gateway/src/test/java/com/oing/restapi/PostApiTest.java index 769dcdd5..eb78512a 100644 --- a/gateway/src/test/java/com/oing/restapi/PostApiTest.java +++ b/gateway/src/test/java/com/oing/restapi/PostApiTest.java @@ -8,15 +8,12 @@ import com.oing.repository.PostRepository; import com.oing.repository.MemberRepository; import com.oing.service.TokenGenerator; -import com.oing.support.EmbeddedRedisConfig; -import com.oing.support.RedisTestConfig; import jakarta.transaction.Transactional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Import; import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; @@ -31,7 +28,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @SpringBootTest -@Import({EmbeddedRedisConfig.class, RedisTestConfig.class}) @Transactional @ActiveProfiles("test") @AutoConfigureMockMvc diff --git a/gateway/src/test/java/com/oing/support/EmbeddedRedisConfig.java b/gateway/src/test/java/com/oing/support/EmbeddedRedisConfig.java deleted file mode 100644 index 2fc4ccfe..00000000 --- a/gateway/src/test/java/com/oing/support/EmbeddedRedisConfig.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.oing.support; - -import jakarta.annotation.PostConstruct; -import jakarta.annotation.PreDestroy; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Profile; -import org.springframework.data.redis.RedisConnectionFailureException; -import redis.embedded.RedisServer; - -import java.io.File; - -@TestConfiguration -@Profile("test") -public class EmbeddedRedisConfig { - - @Value("${spring.data.redis.port}") - private int port; - - private RedisServer redisServer; - - @PostConstruct - public void startRedis() { - try { - redisServer = RedisServer.builder() - .port(port) - .setting("maxmemory 256M") - .build(); - redisServer.start(); - - } catch (RuntimeException e) { // Run redis manually - redisServer = new RedisServer(new File("/usr/local/bin/redis-server"), port); - redisServer.start(); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @PreDestroy - public void stopRedis() { - redisServer.stop(); - } -} diff --git a/gateway/src/test/java/com/oing/support/RedisTestConfig.java b/gateway/src/test/java/com/oing/support/RedisTestConfig.java deleted file mode 100644 index cd854d5a..00000000 --- a/gateway/src/test/java/com/oing/support/RedisTestConfig.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.oing.support; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Profile; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.connection.RedisStandaloneConfiguration; -import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; -import org.springframework.data.redis.serializer.StringRedisSerializer; - -@Profile("test") -@TestConfiguration -public class RedisTestConfig { - - @Value("${spring.data.redis.host}") - private String redisHost; - - @Value("${spring.data.redis.port}") - private int redisPort; - - @Bean - public RedisConnectionFactory redisConnectionFactory() { - return new LettuceConnectionFactory(new RedisStandaloneConfiguration(redisHost, redisPort)); - } - - @Bean - public RedisTemplate redisTemplate() { - RedisTemplate redisTemplate = new RedisTemplate<>(); - redisTemplate.setConnectionFactory(redisConnectionFactory()); - redisTemplate.setKeySerializer(new StringRedisSerializer()); - - /* Java 기본 직렬화가 아닌 JSON 직렬화 설정 */ - redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); - - return redisTemplate; - } -} diff --git a/post/src/main/java/com/oing/controller/PostController.java b/post/src/main/java/com/oing/controller/PostController.java index 17d6a824..99cc9a2d 100644 --- a/post/src/main/java/com/oing/controller/PostController.java +++ b/post/src/main/java/com/oing/controller/PostController.java @@ -14,7 +14,6 @@ import com.oing.service.PostService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.cache.annotation.CacheEvict; import org.springframework.stereotype.Controller; import java.time.LocalDate; @@ -52,8 +51,6 @@ public PaginationResponse fetchDailyFeeds(Integer page, Integer si } @Override - @CacheEvict(value = "calendarCache", - key = "#loginFamilyId.concat(':').concat(T(java.time.format.DateTimeFormatter).ofPattern('yyyy-MM').format(#request.uploadTime()))") public PostResponse createPost(CreatePostRequest request, String loginFamilyId, String loginMemberId) { log.info("Member {} is trying to create post", loginMemberId); diff --git a/post/src/main/java/com/oing/dto/response/CalendarResponse.java b/post/src/main/java/com/oing/dto/response/CalendarResponse.java index 868e8380..f87c4db3 100644 --- a/post/src/main/java/com/oing/dto/response/CalendarResponse.java +++ b/post/src/main/java/com/oing/dto/response/CalendarResponse.java @@ -1,9 +1,5 @@ package com.oing.dto.response; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; -import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Schema; import org.springframework.format.annotation.DateTimeFormat; @@ -13,8 +9,6 @@ @Schema(description = "캘린더 응답") public record CalendarResponse( @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) - @JsonSerialize(using = LocalDateSerializer.class) - @JsonDeserialize(using = LocalDateDeserializer.class) @Parameter(description = "오늘의 날짜", example = "2023-12-05") LocalDate date,