问题描述
采用了一个博客中的config类,别人的构造可以使用我的却不可以,我该如何解决
问题出现的环境背景及自己尝试过哪些方法
采用RedisTemplate实现Redis分布式锁方案。
相关代码
//缓存管理器
@Bean
public CacheManager cacheManager(@SuppressWarnings("rawtypes") RedisTemplate redisTemplate) {
RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
//设置默认缓存过期时间
cacheManager.setDefaultExpiration(10000);
Map<String, Long> expiresMap = new HashMap<>();
//用户当前行程设置1小时过期
expiresMap.put(RedisConstant.currentTravelsByDriverId, 3600L);
//根据id获取行程详情设置1小时过期
expiresMap.put(RedisConstant.detailTravelsById, 3600L);
cacheManager.setExpires(expiresMap);
return cacheManager;
}
该段代码中RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
redisTemplate为构造参数时候,显示没有该构造参数,源码中没有一个参数的构造。为啥别人博客中可以正常使用,引入我的项目中就不能?是因为springCloud版本问题吗?
有没有解决过这类型问题的老哥帮帮忙,着急!!!!
检查下你的spring-data-redis版本, RedisCacheManager这个类在spring-data-redis包下,我这边spring-data-redis1.8.14.RELEASE是有构造参数的。如果没有直接依赖此包,就检查下是否有传递依赖