首页 > spring @cacheable 注解在底层是ehcache时候如何自动生成cache?

spring @cacheable 注解在底层是ehcache时候如何自动生成cache?

以前用的普通的 currentmap,现在把底层切换成了 ehcache
然后,前面的代码就不能用了。

@Cacheable(key = "'pdf'+#s", value = "sss")

以前这么写,value 的值对应的 cache 如果不存在会自动生成,现在不会,必须在 xml 里声明。。有自动生成的办法吗?


原因很简单。许多在Spring环境下使用的Annotation需要Spring使用AOP拦截,调用相关的库才能生效。而Spring只会在Bean使用AOP。

声明在xml,Spring当然知道要AOP Cacheable的方法。但不在xml声明了,就需要告诉Spring去Scan相关的类了,于是<context:component-scan>登场了。

【热门文章】
【热门文章】