|
@@ -6,6 +6,8 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
|
|
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|
|
+import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
|
|
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|
@@ -14,11 +16,38 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|
|
@AutoConfigureAfter(RedisAutoConfiguration.class)
|
|
|
public class RedisConfig {
|
|
|
|
|
|
- @Autowired
|
|
|
- LettuceConnectionFactory lettuceConnectionFactory;
|
|
|
+// @Autowired
|
|
|
+// LettuceConnectionFactory lettuceConnectionFactory;
|
|
|
+
|
|
|
+// @Bean
|
|
|
+// public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory redisConnectionFactory) {
|
|
|
+// RedisTemplate template = new RedisTemplate();
|
|
|
+// template.setConnectionFactory(redisConnectionFactory);
|
|
|
+//// Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
|
|
|
+// StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
|
|
|
+//
|
|
|
+// /*
|
|
|
+// * Jackson对象映射器(Object Mapper)可以把JSON解析为用户自定义类对象, 或者解析为JSON内置的树模型的对象
|
|
|
+// * DefaultTyping.NON_FINAL,将会为(String、Boolean、Integer、Double)除外的其他类型及非final类型的数组添加反序列化所需要的类型。
|
|
|
+// * JsonTypeInfo.As.PROPERTY,它将包含@class属性,作为序列化的一个属性,值就是完全限定名类型。当前类及其属性都会添加这个名为@class的属性。
|
|
|
+// */
|
|
|
+//// ObjectMapper om = new ObjectMapper();
|
|
|
+//// om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
|
|
+//// om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance , ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
|
|
|
+//// jackson2JsonRedisSerializer.setObjectMapper(om);
|
|
|
+// template.setKeySerializer(stringRedisSerializer);
|
|
|
+// template.setValueSerializer(stringRedisSerializer);
|
|
|
+// template.setHashKeySerializer(stringRedisSerializer);
|
|
|
+// template.setHashValueSerializer(stringRedisSerializer);
|
|
|
+//
|
|
|
+// template.afterPropertiesSet();
|
|
|
+// template.setEnableTransactionSupport(true);
|
|
|
+// return template;
|
|
|
+// }
|
|
|
+
|
|
|
|
|
|
@Bean
|
|
|
- public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory redisConnectionFactory) {
|
|
|
+ public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
|
|
RedisTemplate template = new RedisTemplate();
|
|
|
template.setConnectionFactory(redisConnectionFactory);
|
|
|
// Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
|
|
@@ -39,7 +68,7 @@ public class RedisConfig {
|
|
|
template.setHashValueSerializer(stringRedisSerializer);
|
|
|
|
|
|
template.afterPropertiesSet();
|
|
|
- template.setEnableTransactionSupport(true);
|
|
|
+// template.setEnableTransactionSupport(true);
|
|
|
return template;
|
|
|
}
|
|
|
}
|