com.spring.boxes.option.config.ConfigureAutoConfiguration Maven / Gradle / Ivy
The newest version!
package com.spring.boxes.option.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
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.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Configuration
@EnableAutoConfiguration
public class ConfigureAutoConfiguration {
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Autowired
private RedisConnectionFactory redisConnectionFactory;
// 全局配置文件
@Bean
public Configure configure(){
return Configure.newInstance(stringRedisTemplate);
}
@Bean
public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(connectionFactory);
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(this.jacksonSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashValueSerializer(this.jacksonSerializer());
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
@Bean
public Jackson2JsonRedisSerializer
© 2015 - 2025 Weber Informatics LLC | Privacy Policy