在spring boot整合redis时,本以为springboot已经实现了对redis的完美结合。只需要一个@Autowired就可以使用RedisTemplate模板了,结果项目启动出现了下面的惊喜。。。
很明显让我们指明RedisTemplate在项目中的配置。果然,好记性不如烂笔头,突然想起来在之前的项目中已经使用过redis,其中就有这部分内容,但自己负责的不是这个模块而已,很是尴尬。。。
所以我找到RedisTemplate注册bean.
package com.dsx.redis.configuration;
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.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/***
*
* @ClassName: RedisConfig
* @Description: redis配置类
* @author 曰业而安