top.isopen.commons.springboot.config.RedisConfig Maven / Gradle / Ivy
package top.isopen.commons.springboot.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
import org.redisson.api.RedissonClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
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;
import top.isopen.commons.springboot.helper.RedisHelper;
import top.isopen.commons.springboot.lock.RedLockAspect;
import top.isopen.commons.springboot.lock.RedLocksAspect;
/**
* Redis 配置类
*
* 用于注册 Redis 工具类 {@link RedisHelper}、Redis 分布式锁 {@link RedLockAspect} {@link RedLocksAspect}
*
* @author TimeChaser
* @version 1.0
* @since 2023/7/7 17:03
*/
@Configuration(proxyBeanMethods = false)
public class RedisConfig {
@Bean
@ConditionalOnBean({RedisConnectionFactory.class})
@ConditionalOnMissingBean(name = "serializedRedisTemplate")
public RedisTemplate serializedRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
/*使用 Jackson2JsonRedisSerialize 替换默认序列化*/
Jackson2JsonRedisSerializer
© 2015 - 2024 Weber Informatics LLC | Privacy Policy