|
@@ -1,44 +0,0 @@
|
|
-/*
|
|
|
|
- * *************************************************
|
|
|
|
- * Copyright (c) 2018 QMTH. All Rights Reserved.
|
|
|
|
- * Created by Deason on 2018-08-02 09:21:53.
|
|
|
|
- * *************************************************
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
-package cn.com.qmth;
|
|
|
|
-
|
|
|
|
-import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
|
|
|
-import com.fasterxml.jackson.annotation.PropertyAccessor;
|
|
|
|
-import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
|
-import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
-import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
|
|
|
-import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * @author: fengdesheng
|
|
|
|
- * @since: 2018/8/2
|
|
|
|
- */
|
|
|
|
-@Configuration
|
|
|
|
-public class RedisConfig {
|
|
|
|
-
|
|
|
|
- @Bean
|
|
|
|
- public RedisTemplate<String, Object> strRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
|
|
|
- RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
|
|
|
- Jackson2JsonRedisSerializer<?> jacksonSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
|
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
- objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
|
|
|
- objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
|
|
|
|
- objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
|
|
|
- jacksonSerializer.setObjectMapper(objectMapper);
|
|
|
|
- redisTemplate.setValueSerializer(jacksonSerializer);
|
|
|
|
- redisTemplate.setKeySerializer(new StringRedisSerializer());
|
|
|
|
- redisTemplate.setConnectionFactory(redisConnectionFactory);
|
|
|
|
- redisTemplate.afterPropertiesSet();
|
|
|
|
- return redisTemplate;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|