spring 缓存 @Cacheable 错误总结

1.      

NoSuchMethodError:redis.clients.jedis.JedisShardInfo.setTimeout(I)V

Spring结合Jedis,jedis的版本过高。之前为2.9.0,改为低版本就不报错了

<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>2.5.2</version>

</dependency>

2.      

Error creating bean with name'ehcacheManager' defined in class path resource [conf/spring/spring-cache.xml] 

nested exception isjava.NoSuchMethodError:net.sf.ehcheManager......

NoSuchMethodError:没找到资源,有可能是版本不对,有可能是没有导入jar包。若采用maven,需要引入包

3.      

Cache注解没生效

@Cacheable(value = CacheKeys.CACHE_TYEE_REDIS,

key = "T(cache.CacheKeys).CACHE_GAMEKEY+#gameId")

在使用Spring @Cacheable注解的时候,要注意,如果类A的方法f()被标注了@Cacheable注解,那么当类A的其他方法,例如:f2(),去直接调用f()的时候,@Cacheable是不起作用的,原因是@Cacheable是基于Spring AOP代理类,f2()属于内部方法,直接调用f()时,是不走代理的。

解决办法,把f()提取到其他的service层。

猜你喜欢

转载自blog.csdn.net/zj420964597/article/details/81016097