diff --git a/src/main/java/com/ycwl/basic/config/CustomRedisCacheManager.java b/src/main/java/com/ycwl/basic/config/CustomRedisCacheManager.java index dcbe1de2..3a1587b5 100644 --- a/src/main/java/com/ycwl/basic/config/CustomRedisCacheManager.java +++ b/src/main/java/com/ycwl/basic/config/CustomRedisCacheManager.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator; import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator; -import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -24,19 +24,12 @@ import java.time.Duration; */ @Configuration @EnableCaching -public class CustomRedisCacheManager extends CachingConfigurerSupport { +public class CustomRedisCacheManager { + @Autowired + private ObjectMapper objectMapper; @Bean public RedisCacheConfiguration redisCacheConfiguration() { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JavaTimeModule()); - - // Configure type handling to prevent ClassCastException - PolymorphicTypeValidator typeValidator = BasicPolymorphicTypeValidator.builder() - .allowIfBaseType(Object.class) - .build(); - objectMapper.activateDefaultTyping(typeValidator, ObjectMapper.DefaultTyping.NON_FINAL); - Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(objectMapper, Object.class); RedisCacheConfiguration configuration = RedisCacheConfiguration.defaultCacheConfig();