同一个类里@Cacheable缓存不起作用

问题原因:

注解@Cacheable是使用AOP代理实现的 ,通过创建内部类来代理缓存方法,类内部的方法调用类内部的缓存方法不会走代理,所以就不能正常创建缓存,所以每次都需要去调用数据库。

解决方法:

方法1(注入自己):

@Autowired
LayerService service;

方法2:

使用AspectJ,这个方式太复杂,有时间再试

相关资源:

https://www.cnblogs.com/cyhbyw/p/8615816.html

https://stackoverflow.com/questions/16899604/spring-cache-cacheable-not-working-while-calling-from-another-method-of-the-s/48867068#48867068

原文地址:https://www.cnblogs.com/SmilingEye/p/11690976.html