JedisUtil$Keys报错
来源:11-4 引入缓存技术之配置讲解
Caeser110
2018-11-30
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘collegeServiceImpl’: Unsatisfied dependency expressed through field ‘jedisKeys’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.caeser.studentUnionSys.cache.JedisUtil$Keys’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
11月 30, 2018 11:56:15 上午 org.springframework.test.context.TestContextManager prepareTestInstance
严重: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@3cd3e762] to prepare test instance [com.caeser.studentUnionSys.service.CollegeServiceTest@3c0036b]
java.lang.IllegalStateException: Failed to load ApplicationContext
老师,在使用redis的时候报错,提示没有这个bean是怎么回事
2回答
-
慕标25604
2019-01-28
同学,请问你这个问题解决了吗?我也遇到了,百度了好几天没找到,配置什么的也核对了几次没问题,如果解决了分享一下呀
182019-01-28 -
翔仔
2018-11-30
同学好,遇到这个问题,只能靠同学检查下相关的配置,spring-redis.xml里面是不是已经把keys加入进来了
<!-- Redis的key操作 --> <bean id="jedisKeys" class="com.imooc.o2o.cache.JedisUtil$Keys" scope="singleton"> <constructor-arg ref="jedisUtil"></constructor-arg> </bean>
同时在JedisUtil里,是不是已经设置上相关的Keys
public class Keys { /** * 清空所有key */ public String flushAll() { Jedis jedis = getJedis(); String stata = jedis.flushAll(); jedis.close(); return stata; } /** * 更改key * * @param String * oldkey * @param String * newkey * @return 状态码 */ public String rename(String oldkey, String newkey) { return rename(SafeEncoder.encode(oldkey), SafeEncoder.encode(newkey)); } /** * 更改key,仅当新key不存在时才执行 * * @param String * oldkey * @param String * newkey * @return 状态码 */ public long renamenx(String oldkey, String newkey) { Jedis jedis = getJedis(); long status = jedis.renamenx(oldkey, newkey); jedis.close(); return status; } /** * 更改key * * @param String * oldkey * @param String * newkey * @return 状态码 */ public String rename(byte[] oldkey, byte[] newkey) { Jedis jedis = getJedis(); String status = jedis.rename(oldkey, newkey); jedis.close(); return status; } /** * 设置key的过期时间,以秒为单位 * * @param String * key * @param 时间 * ,已秒为单位 * @return 影响的记录数 */ public long expired(String key, int seconds) { Jedis jedis = getJedis(); long count = jedis.expire(key, seconds); jedis.close(); return count; } /** * 设置key的过期时间,它是距历元(即格林威治标准时间 1970 年 1 月 1 日的 00:00:00,格里高利历)的偏移量。 * * @param String * key * @param 时间 * ,已秒为单位 * @return 影响的记录数 */ public long expireAt(String key, long timestamp) { Jedis jedis = getJedis(); long count = jedis.expireAt(key, timestamp); jedis.close(); return count; } /** * 查询key的过期时间 * * @param String * key * @return 以秒为单位的时间表示 */ public long ttl(String key) { // ShardedJedis sjedis = getShardedJedis(); Jedis sjedis = getJedis(); long len = sjedis.ttl(key); sjedis.close(); return len; } /** * 取消对key过期时间的设置 * * @param key * @return 影响的记录数 */ public long persist(String key) { Jedis jedis = getJedis(); long count = jedis.persist(key); jedis.close(); return count; } /** * 删除keys对应的记录,可以是多个key * * @param String * ... keys * @return 删除的记录数 */ public long del(String... keys) { Jedis jedis = getJedis(); long count = jedis.del(keys); jedis.close(); return count; } /** * 删除keys对应的记录,可以是多个key * * @param String * ... keys * @return 删除的记录数 */ public long del(byte[]... keys) { Jedis jedis = getJedis(); long count = jedis.del(keys); jedis.close(); return count; } /** * 判断key是否存在 * * @param String * key * @return boolean */ public boolean exists(String key) { // ShardedJedis sjedis = getShardedJedis(); Jedis sjedis = getJedis(); boolean exis = sjedis.exists(key); sjedis.close(); return exis; } /** * 对List,Set,SortSet进行排序,如果集合数据较大应避免使用这个方法 * * @param String * key * @return List<String> 集合的全部记录 **/ public List<String> sort(String key) { // ShardedJedis sjedis = getShardedJedis(); Jedis sjedis = getJedis(); List<String> list = sjedis.sort(key); sjedis.close(); return list; } /** * 对List,Set,SortSet进行排序或limit * * @param String * key * @param SortingParams * parame 定义排序类型或limit的起止位置. * @return List<String> 全部或部分记录 **/ public List<String> sort(String key, SortingParams parame) { // ShardedJedis sjedis = getShardedJedis(); Jedis sjedis = getJedis(); List<String> list = sjedis.sort(key, parame); sjedis.close(); return list; } /** * 返回指定key存储的类型 * * @param String * key * @return String string|list|set|zset|hash **/ public String type(String key) { // ShardedJedis sjedis = getShardedJedis(); Jedis sjedis = getJedis(); String type = sjedis.type(key); sjedis.close(); return type; } /** * 查找所有匹配给定的模式的键 * * @param String * key的表达式,*表示多个,?表示一个 */ public Set<String> keys(String pattern) { Jedis jedis = getJedis(); Set<String> set = jedis.keys(pattern); jedis.close(); return set; } }
00
相似问题