| 
														
															@@ -1,5 +1,9 @@ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 package com.tzld.longarticle.recommend.server.config; 
														 | 
														
														 | 
														
															 package com.tzld.longarticle.recommend.server.config; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+import com.fasterxml.jackson.annotation.JsonAutoDetect; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+import com.fasterxml.jackson.annotation.PropertyAccessor; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+import com.fasterxml.jackson.databind.ObjectMapper; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import org.apache.commons.pool2.impl.GenericObjectPoolConfig; 
														 | 
														
														 | 
														
															 import org.apache.commons.pool2.impl.GenericObjectPoolConfig; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import org.springframework.beans.factory.annotation.Qualifier; 
														 | 
														
														 | 
														
															 import org.springframework.beans.factory.annotation.Qualifier; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import org.springframework.boot.context.properties.ConfigurationProperties; 
														 | 
														
														 | 
														
															 import org.springframework.boot.context.properties.ConfigurationProperties; 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -12,6 +16,8 @@ import org.springframework.data.redis.connection.lettuce.LettuceClientConfigurat 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; 
														 | 
														
														 | 
														
															 import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration; 
														 | 
														
														 | 
														
															 import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import org.springframework.data.redis.core.RedisTemplate; 
														 | 
														
														 | 
														
															 import org.springframework.data.redis.core.RedisTemplate; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+import org.springframework.data.redis.serializer.RedisSerializer; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import org.springframework.data.redis.serializer.StringRedisSerializer; 
														 | 
														
														 | 
														
															 import org.springframework.data.redis.serializer.StringRedisSerializer; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 @Configuration 
														 | 
														
														 | 
														
															 @Configuration 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -39,7 +45,7 @@ public class RedisTemplateConfig { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															     @Bean(name = "redisTemplate") 
														 | 
														
														 | 
														
															     @Bean(name = "redisTemplate") 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    public RedisTemplate<String, String> getRedisTemplate(@Qualifier("redisFactory") RedisConnectionFactory factory) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    public RedisTemplate<String, Object> getRedisTemplate(@Qualifier("redisFactory") RedisConnectionFactory factory) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         return buildRedisTemplateByString(factory); 
														 | 
														
														 | 
														
															         return buildRedisTemplateByString(factory); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -49,15 +55,24 @@ public class RedisTemplateConfig { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															      * @param factory 
														 | 
														
														 | 
														
															      * @param factory 
														 | 
													
												
											
												
													
														| 
														 | 
														
															      * @return 
														 | 
														
														 | 
														
															      * @return 
														 | 
													
												
											
												
													
														| 
														 | 
														
															      */ 
														 | 
														
														 | 
														
															      */ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    public RedisTemplate<String, String> buildRedisTemplateByString(RedisConnectionFactory factory) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        RedisTemplate<String, String> redisTemplate = new RedisTemplate<>(); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    public RedisTemplate<String, Object> buildRedisTemplateByString(RedisConnectionFactory factory) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         redisTemplate.setConnectionFactory(factory); 
														 | 
														
														 | 
														
															         redisTemplate.setConnectionFactory(factory); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        // key的序列化类型 保证可读性 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        redisTemplate.setValueSerializer(redisSerializer()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         redisTemplate.setKeySerializer(new StringRedisSerializer()); 
														 | 
														
														 | 
														
															         redisTemplate.setKeySerializer(new StringRedisSerializer()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        redisTemplate.setValueSerializer(new StringRedisSerializer()); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         redisTemplate.setHashKeySerializer(new StringRedisSerializer()); 
														 | 
														
														 | 
														
															         redisTemplate.setHashKeySerializer(new StringRedisSerializer()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        redisTemplate.setHashValueSerializer(new StringRedisSerializer()); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        redisTemplate.setHashValueSerializer(redisSerializer()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        redisTemplate.afterPropertiesSet(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         return redisTemplate; 
														 | 
														
														 | 
														
															         return redisTemplate; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    public RedisSerializer<Object> redisSerializer() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        //创建JSON序列化器 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        ObjectMapper objectMapper = new ObjectMapper(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        //必须设置,否则无法序列化实体类对象 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        return new GenericJackson2JsonRedisSerializer(objectMapper); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 } 
														 | 
														
														 | 
														
															 } 
														 |