经过查找首先确保
1、redis jar包正确导入
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2、RedisUtils 类添加注解 @Component
/**
* redis工具
* @author admin
*
*/
@Component
public class RedisUtils {
private static Integer CACHE_DATE = 10; //redis 失效时间
@Resource
private RedisTemplate<String, Object> redisTemplate;
}
3、service实现类中注入RedisUtils 对象
/**
* 用户
*
* @author admin
*
*/
@Service
public class UserServiceImpl implements IUserService {
@Resource
private RedisUtils redisUtils;
}
4、redis 信息配置完成
# Redis数据库索引(默认为0)
spring.redis.database=0
# Redis服务器地址
spring.redis.host=127.0.0.1
#spring.redis.host=127.0.0.1
#spring.redis.host=202.113.215.3
# Redis服务器连接端口
spring.redis.port=6379
#spring.redis.port=8993
# Redis服务器连接密码(默认为空)
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.pool.max-active=8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.pool.min-idle=0
# 连接超时时间(毫秒)
#spring.redis.timeout=1000*10