Java Spring-ehcache-#root.targetClass值,如果返回类型为List<;用户>;?
我有以下方法:Java Spring-ehcache-#root.targetClass值,如果返回类型为List<;用户>;?,java,spring,ehcache,Java,Spring,Ehcache,我有以下方法: @Cacheable(value="settings", key = "#root.targetClass") @Override public List<MySeeting> getAll() { return Lists.newArrayList(settingRepository.findAll()); } @Cacheable(value=“settings”,key=“#root.targetClass”) @凌驾 公共列表getAll(){
@Cacheable(value="settings", key = "#root.targetClass")
@Override
public List<MySeeting> getAll() {
return Lists.newArrayList(settingRepository.findAll());
}
@Cacheable(value=“settings”,key=“#root.targetClass”)
@凌驾
公共列表getAll(){
return Lists.newArrayList(settingRepository.findAll());
}
#root.targetClass的值是多少?
列出targetClass
是被调用目标的类,即调用方法的对象的类型。所以它与方法的返回类型无关
在任何情况下,由于Java中的泛型擦除,访问返回类型只会给您类型
列表
我找到了我正在寻找的答案,我在谷歌上发现了以下代码:
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”实际上是“class com.test.service.impl.MyService”(MyService类是声明上述getAll方法的地方)