我有以下方法:
@Cacheable(value="settings", key = "#root.targetClass")
@Override
public List<MySeeting> getAll() {
return Lists.newArrayList(settingRepository.findAll());
}
#root.targetClass的值是多少?LIST&LT;myseeting>或myseeting?
我正在使用春季4和ehcache。
欢呼!
我找到了我要寻找的答案,我发现该代码谷歌搜索:
public void getCache() {
Object nativeCache = cacheManager.getCache("mycache").getNativeCache();
if (nativeCache instanceof net.sf.ehcache.Ehcache) {
net.sf.ehcache.Ehcache ehCache = (net.sf.ehcache.Ehcache) nativeCache;
ehCache.getKeys();
}
}
通过检查" ehcache.getkeys()",我可以看到"#root.targetClass"实际上是" com.test.service.impl.myservice"类(myService类是上述getall方法,上面提到的getall方法已声明)
根据文档targetClass
是被调用的目标类,即调用该方法的对象的类型。因此,它与方法的返回类型无关。
无论如何,由于Java中的仿制药擦除,可以访问返回类型,只会为您提供类型List
。