首页 > 解决方案 > 会话范围 CacheManager 不能在 @Cacheable 中使用。如何解决?

问题描述

我有两个带有单例(这个是主要的)和会话范围的缓存管理器。我指出,在 MyRepository 类中,我想通过方法上的以下注释使用“sessionBasedCache”:

@Cacheable(value = "members", key = "#id.value()", cacheManager = "sessionBasedCache")
...

当“sessionBasedCache”被调用时,我得到了这个异常:

setAttribute: Non-serializable attribute with name scopedTarget.epeSessionBasedCache

这是我的配置:

@Bean(name = "sessionBasedCache")
@Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)
public CacheManager epeSessionBasedCacheManager() {
    return new GuavaCacheManager();
}

我已经尝试过:如果我在单例范围内使用缓存,一切都很好。我查看了 SimpleCacheManager,它是默认的弹簧缓存。而且它没有实现可序列化。

您对发生的事情以及如何解决它有任何想法吗?

标签: springspring-mvccaching

解决方案


推荐阅读