배포 서버 배치 실행 시 직렬화 문제 - Genie-Uss/genieus GitHub Wiki

문제

  • Redis에 저장된 JSON 문자열GenericJackson2JsonRedisSerializer 또는 ObjectMapper로 역직렬화할 때 오류 발생.
  • 로컬 서버에서는 발생하지 않았던 문제로 배포 서버의 배치 실행 시에만 발생
  • 배포 서버에서는 @class 정보가 없다는 오류, 혹은 역직렬화 실패.

원인

  • 실행 환경에 따라 직렬화된 JSON 클래스 정보가 매핑되지 않을 수 있음
  • 데이터 직렬화 시에 RedisTemplate의 타입을 Object로 사용하였고, 이는 배포 환경에서 정확한 @Class 정보를 전달하지 못함
  • 특히 @class 정보는 직렬화/역직렬화 양쪽 환경이 정확히 맞아야만 작동한다."

해결

  • Redis 데이터 저장 시 사용되는 RedisTemplate의 타입을 Object → String으로 수정

AS-IS

  // RedisReader & RedisWriter
  @Slf4j
	@Component
	@RequiredArgsConstructor
	public class CouponRedisWrite implements ItemWriter<IssueCouponCommand> {
	  private final ObjectMapper objectMapper;
	  private final CouponUserJpaRepository couponUserJpaRepository;
	  **private final RedisTemplate<String, Object> redisTemplate;**

TO-BE

  // RedisReader & RedisWriter
  @Slf4j
	@Component
	@RequiredArgsConstructor
	public class CouponRedisWrite implements ItemWriter<IssueCouponCommand> {
	  private final ObjectMapper objectMapper;
	  private final CouponUserJpaRepository couponUserJpaRepository;
	  **private final StringRedisTemplate redisTemplate;**