Explorar el Código

修复redis缓存乱码问题

NorthLan hace 7 años
padre
commit
fced6f7cf7

+ 7 - 2
zen-core/src/main/kotlin/com/gxzc/zen/common/config/cache/redis/RedisConfig.kt

@@ -1,5 +1,7 @@
 package com.gxzc.zen.common.config.cache.redis
 
+import com.fasterxml.jackson.databind.DeserializationFeature
+import com.fasterxml.jackson.databind.ObjectMapper
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
 import org.springframework.cache.CacheManager
 import org.springframework.cache.annotation.EnableCaching
@@ -7,6 +9,7 @@ import org.springframework.context.annotation.Bean
 import org.springframework.context.annotation.Configuration
 import org.springframework.data.redis.cache.RedisCacheManager
 import org.springframework.data.redis.core.RedisTemplate
+import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer
 import org.springframework.data.redis.serializer.StringRedisSerializer
 
 /**
@@ -24,8 +27,10 @@ class RedisConfig {
     @Bean
     fun cacheManager(redisTemplate: RedisTemplate<Any, Any>): CacheManager {
         return RedisCacheManager(redisTemplate.apply {
-            keySerializer = StringRedisSerializer()
-            hashKeySerializer = StringRedisSerializer()
+            val stringRedisSerializer = StringRedisSerializer()
+            keySerializer = stringRedisSerializer
+            hashKeySerializer = stringRedisSerializer
+            valueSerializer = GenericJackson2JsonRedisSerializer()
         })
     }
 }